At the request of some of our readers, this week, we’ll examine just how easy it is to send emails with attachments using Gmail. With raw PHP, this would be a long and tedious task. However, with CodeIgniter, it’s a cinch! I’ll show you how in this eighteen minute video tutorial.
Catch Up
Day 3
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for more daily web development tuts and articles.



RoyalSlider – Touch-Enable ... only $12.00 
Awesome Tutorials dude… Thanks a lot… I am learning real codeIgniter from your tutorials.. Plz keep going….
Great
But i have a error:
Call to undefined method CI_Controller::controller() in C:\wamp\www\ci\application\controllers\email.php on line 10
Here is my code:
class Email extends Ci_Controller{
function __construct()
{
parent:: controller();
}
function index()
{
$config = Array(
‘protocol’=>’smtp’,
‘smtp_host’=>’ssl://smtp.googlemail.com’,
‘smtp_port’=>465,
‘smtp_user’=>’myemail’,
‘smtp_pass’=>’mypass’
);
/*forbinder til libary */
$this->load->libary(‘email’, $config);
$this->email->set_newline(“\r\n”);
/*afsenderen*/
$this->email->from(‘nettutsTutorials@gmail.com’);
/*modtageren*/
$this->email->to(‘renefrisker@gmail.com’);
$this->email->subject(‘Det er en email test’);
$this->email->messange(‘Det virke sku’);
if($this->email->send()){
echo’Din mail bliv sent’;
}
else
{
show_error($this->email->print_debugger());
}
}
}
@mrChub: Look at the previous comment page, you will find the answer there. It has to do with the version nr of CodeIgniter. This tutorial is based on 1.7, you’re propably using 2.1.
In construct function is: parent::__construct();
This is for Codeigniter 2.0.
I was getting the same error. I came here after already changing my code to your solution, but I’m now getting a 504 error.
Gateway Time-out
The gateway did not receive a timely response from the upstream server or application.
Any thoughts?
i have a error:
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553
can any one help
Fantastic series, thanks for making these.
I am writing exactly the same code but I’m getting error like “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 I get rid of the ssl part it didn’t work again
Having the same problem here… anyone?
“Possible error – “Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?”
If you got this error, like I did, then you need to enable SSL in your PHP config. Load up php.ini and find a line with the following:
;extension=php_openssl.dll
Simply remove the “;” and then restart Apache and you’re good to go. The “;” denotes that the line is a comment, and so removing it enables the SSL extension for Apache. Credit – http://www.boringguys.com/2007/07/20/unable-to-find-the-socket-transport-ssl-did-you-forget-to-enable-it-when-you-configured-php/”
http://joelg.info/sending-email-with-gmail-using-the-codeignite
Nice Tutorial
Man just keep up with good work! Your tutorials really helps, thank you so much!
Thank you so much for this series!!!! This has been so helpful in learning CodeIgniter!!!!
you are using live server or local server for email to gmail??????????
email is sent and no error occur but when i open my gmail account there was no email.
But the message “your email is sent ,fool” was printed on browser
please tell me the solution
awesome tutorials! thanks for taking the time to make them :) keep them coming…
I love these tutorials. Thanks so much for teaching.
Thanks for sharing mate, these are just great tutorials!
This tutorial uses an older version of Code Igniter 1.7? So I made the adjustments for the CI_2.1 using the parent::__construct, but somehow I am still drawing a blank page from my URL http://localhost/shell/index.php/email/index. NO EMAIL WAS SENT FOOL….What should I do to get this to work? I can’t move onto the next tutorial and its frustrating :-/ Thanks in advance!
‘smtp’,
‘smtp_host’ => ‘ssl://smtp.googlemail.com’,
‘smtp_port’ => 465,
‘smtp_user’ => ‘user’,
‘smtp_pass’ => ‘pass’
);
$this->load->library(‘email’);
$this->email->set_newline(“\r\n”);
$this->email->from(‘rezapiri@gmail.com’, ‘Top Dog’);
$this->email->to(‘rezapiri@gmail.com’);
$this->email->subject(‘This is an email test’);
$this->email->message(‘Its working’);
if($this->email-send())
{
echo ‘Your email was sent fool.’;
}
else
{
show_error($this->email->print_debugger());
}
}
}
the last post didn’t capture the controller etc…
‘smtp’,
‘smtp_host’ => ‘ssl://smtp.googlemail.com’,
‘smtp_port’ => 465,
‘smtp_user’ => ‘user’,
‘smtp_pass’ => ‘pass’
);
$this->load->library(‘email’);
$this->email->set_newline(“\r\n”);
$this->email->from(‘rezapiri@gmail.com’, ‘Top Dog’);
$this->email->to(‘rezapiri@gmail.com’);
$this->email->subject(‘This is an email test’);
$this->email->message(‘Its working’);
if($this->email-send())
{
echo ‘Your email was sent fool.’;
}
else
{
show_error($this->email->print_debugger());
}
}
}
Ur videos r really very much helpful….thnks.. :)
Thanks for all you did. It’s very very good stuff. These videos can teach me a lot!!!