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 .
<?php
/**
* SENDS EMAIL WITH GMAIL
*/
class Email extends Controller
{
function __construct()
{
parent::Controller();
}
function index()
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'learneverydaytutorials@gmail.com';
$config['smtp_pass'] = 'learneveryd@ytutorials';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('learneverydaytutorials@gmail.com', 'Arifur Rahman');
$this->email->to('learneverydayTutorials@gmail.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
if($this->email->send())
{
echo 'Your email was sent, successfully.';
}
else
{
show_error($this->email->print_debugger());
}
}
}
?>
After make the file with above code open your browser and go to
[smProductImageAdd src="http://learneveryday.net/codecanyon/adverticement/add_codecnayon_smart-social-share-php.png" alt= "Smart Social Share" href="http://codecanyon.net/item/php-smart-social-share/202558" 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://smtp.googlemail.com:465 (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 .

Restart your Apache. Now again check http://localhost:85/CodeIgniter/ci_series_2/index.php/emai and you will see the bellow message.

Now we login our gmail account and check our mail and we will see the message like this.

Now you can check in your local server to send mail using smtp via gmail.


found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later
Whay about if I can’t configure de ssl option on the hosting server… ?….
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??
thanks….
hi…
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://smtp.googlemail.com:465 (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
Yahoo didn’t give option to send pop up support.
working great
hi, this are working nice on yahoo, but why in gmail it’s in on the spam? thx
It works perfect
Thanks
Thanks a lot. That’s working fine…