Sending Email in CodeIgniter with gmail-series-2

Send mail in codeigniter is easy but using smtp by google is little tricky. Today we will show you how to send mail with smtp in gmail . Type the bellow code in your email.php in \application\controllers location. For us it is D:\xampp\htdocs\CodeIgniter\ci_series_2\application\controllers .


class Email extends Controller
	function __construct()
	function index() 

		$config['protocol'] = 'smtp';
		$config['smtp_host'] = 'ssl://';
		$config['smtp_port'] = 465;
		$config['smtp_user'] = '';
		$config['smtp_pass'] = 'learneveryd@ytutorials';

		$this->load->library('email', $config);
		$this->email->from('', 'Arifur Rahman');
		$this->email->subject('This is an email test');		
		$this->email->message('It is working. Great!');
			echo 'Your email was sent, successfully.';


After make the file with above code open your browser and go to

[smProductImageAdd src="" alt= "Smart Social Share" href="" title="Smart Social Share (Php Plugin)" description="Smart Social share is a php plugin . Which helps you to give user to share your content with social book mark site. There are 4 plugin in this package." ref="marifdu"]

http://localhost:85/CodeIgniter/ci_series_2/index.php/email location to see the file work or not.
But is show this error.

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl:// (Connection timed out)

Filename: libraries/Email.php

Line Number: 1652

This error show because our ssl port is close. So open your php.ini (D:\xampp\php) and go to extension=php_openssl.dll and un comment this line .
php.ini ssl enabled
Restart your Apache. Now again check http://localhost:85/CodeIgniter/ci_series_2/index.php/emai and you will see the bellow message.
mail successful  send
Now we login our gmail account and check our mail and we will see the message like this.
gmail account message show
Now you can check in your local server to send mail using smtp via gmail.


the coder

9 Comments on "Sending Email in CodeIgniter with gmail-series-2"

  1. pharmacy tech says:

    found your site on today and really liked it.. i bookmarked it and will be back to check it out some more later

  2. Whay about if I can’t configure de ssl option on the hosting server… ?….

  3. fachran says:

    when i submit the form, appeared a error message like this :

    An Error Was Encountered

    Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

    i have no idea about this error message,,,and can you help me to solve this problem??


  4. ivm says:

    thanks for your tutorial..

    im using wamp server..
    and i had change my php_openssl

    but displaying eror like this A PHP Error was encountered

    Severity: Warning

    Message: fsockopen() [function.fsockopen]: unable to connect to ssl:// (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )

    Filename: libraries/Email.php

    Line Number: 1652

    i hope you can help me…thankyou so much

  5. admin says:

    Yahoo didn’t give option to send pop up support.

  6. aditia says:

    hi, this are working nice on yahoo, but why in gmail it’s in on the spam? thx

  7. Annie says:

    It works perfect

  8. Umer says:

    Thanks a lot. That’s working fine…

Got something to say? Go for it!


More in ci_series (2 of 3 articles)