:: if you never try you never know ::

software development and best practice

Sending Gmail Email Using CodeIgniter


I have try some library of CI framework. One of them is Email Library. With this library we can send email easily.  This is the script.

Code

//set email library configuration
 $config = Array(
 'protocol' => 'smtp',
 'smtp_host' => 'ssl://smtp.googlemail.com',
 'smtp_port' => 465,
 'smtp_user' => 'yourgoogleaccount@googlemail.com',
 'smtp_pass' => 'yourgooglepassowrd',
 );

 //load email library
 $this->load->library('email', $config);
 $this->email->set_newline("\r\n");

 //set email information and content
 $this->email->from('sembiring.adi@googlemail.com', 'Your Name');
 $this->email->to('sembiring.adi@gmail.com');

 $this->email->subject(' CodeIgniter Rocks Socks ');
 $this->email->message('Hello World');

 if($this->email->send())
 {
 echo 'Your email was sent, fool.';
 }

 else
 {
 show_error($this->email->print_debugger());
 }

Error Posibility

Message: mail() [function.mail]: Failed to connect to mailserver at “ssl://smtp.googlemail.com” port 465, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()

or

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)

If those error occurred, make sure extension=php_smtp.dll and extension=php_openssl.dll uncommented in php.ini . and if you use xampp make sure you change php.ini in xampp/apache/bin/php.ini. If php.ini doesn’t exists to that directory, copy php.ini from xampp/php/php.ini to xampp/apache/bin/.

Oke …, See You !

References

  1. Nettuts Screencast 3 – Sending Email

8 Responses to Sending Gmail Email Using CodeIgniter

  1. ivn September 17, 2010 at 3:52 am

    thank you so much for your tutorial..
    butt..i will try to find extension=php_openssl.dll..but not found..
    could you tell me..line of extension=php_openssl.dll in php.ini

    thanks before

  2. Milan December 24, 2010 at 2:36 pm

    Hi, thanks for the great tutorial..
    I have same problem as ivn, I can’t send an email, when I try to reload the page it take to long to open. I was looking for the php_openssl and php_smtp in my php.ini but I couldn’t find it. Can you tell me how to configure my Lamp settings?
    Im am ruuning ubuntu 10.10.
    Thanks

  3. Eugen March 31, 2011 at 4:21 pm

    Thanks, it worked for me too!

  4. Ali Abbas June 23, 2011 at 10:45 am

    How we can set these values in php.ini

  5. kaory October 17, 2011 at 6:29 am

    how configure php.ini if the project has been upload or hosting??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.