How to send mail using CodeIgniter and smtp

Leave a Comment

Send mail using codeIgniter and smtp



Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.In the past, I have used the email helper extensively in combination with sendmail, however for a new project I was required to route e-mail through a third-party SMTP server, in this case Gmail. I used the following code:
 function sendMail()
 {
     $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx@gmail.com', // change it to yours
    'smtp_pass' => 'xxx', // change it to yours
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
  );

       $message = '';
       $this->load->library('email', $config);
       $this->email->set_newline("\r\n");  
       $this->email->from('xxx@gmail.com'); // change it to yours
       $this->email->to('xxx@gmail.com');// change it to yours
       $this->email->subject('CodeIgniter and smtp');
       $this->email->message('send mail using CodeIgniter and smtp');
     if($this->email->send())
     {
       echo 'Email sent.';
     }
     else
     {
      show_error($this->email->print_debugger());
     }

 }







Helpful links


0 comments:

Post a Comment

Powered by Blogger.