phpmailer for codeigniter (ci)
on our new server we was getting problem with mail sending. yahoo and some other mail server was not receiving our mails to there inbox. so i imported the most popular php class (phpmailer ) in codeigniter as plugin. it’s install and use is too simple. you have to download the zip file from here, then unzip it to your plugin (system\plugins) folder. then edit phpmailer_pi.php , and edit the default configuration as needed as your mail server (default configuration will work fine with gmail smtp, you only have to edit the user name and pass) .
download:
usage:
you can now use all the functions that phpmailer supported. here is a the example that you will get in phpmailer site, but in ci format.
< ?php /* * Created on May 19, 2008 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ class Action extends Controller { function Action() { parent::Controller(); } function testMailer() { error_reporting(E_ERROR); $this->load->plugin('phpmailer'); $mail=new PHPMailer(); /*$mail->IsSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port $mail->Username = "username@somedomain.com"; // GMAIL username $mail->Password = "xxxxxx"; // GMAIL password */ $mail->From = "username@somedomain.com"; $mail->FromName = "sender name"; $mail->Subject = "This is the subject"; $mail->Body = "Hi,This is the HTML BODY"; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body //print_r($mail); $mail->WordWrap = 50; // set word wrap $mail->AddAddress("someone@somedomain.com"); $mail->AddReplyTo("username@somedomain.com","sender name"); $mail->AddAttachment("/path/to/file.zip"); // attachment $mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment $mail->IsHTML(true); // send as HTML if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; } } } ?> |
Popularity: unranked [?]
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
I am S. M. Ibrahim lavlu aka lavluda working as web application developer, SEO, server security and optimization, apps scaling consultant from dhaka, bangladesh. On my free time i like to pass my time for opensource projects.




A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtpdomain.com:444 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)
Filename: plugins/class.smtp.php
Line Number: 121
Mailer Error: SMTP Error: Could not connect to SMTP host.
If i dont use “$mail->SMTPSecure = “ssl”;” (in core php test) it works fine.
Any Help?
[Reply]
lavluda Reply:
August 28th, 2009 at 10:44 pm
looks like your mail server don’t need ssl, so just comment it .
[Reply]
I am getting this error vaia
can u help me out here?
“Mailer Error: SMTP Error: Could not connect to SMTP host.”
[Reply]
Your solution was perfect for me. I cannot thank you enough for this. Don’t know if you are a God believing man but God Bless you anyway.
PS: HE will you know.
Keep them solutions coming dude.
[Reply]
lavluda Reply:
October 6th, 2009 at 9:51 pm
it really nice to hear that my solution worked for you. thanks for comment, this type of comment helps me to work for community.
btw, i believe in god
[Reply]
It doesn’t work me bro
can you help me?
“Mailer Error: SMTP Error: Could not connect to SMTP host.”
[Reply]
lavluda Reply:
October 8th, 2009 at 1:52 pm
hi, did you configured it correctly ?
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = “ssl”; // sets the prefix to the servier
$mail->Host = “smtp.gmail.com”; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = “username@somedomain.com”; // GMAIL username
$mail->Password = “xxxxxx”; “
[Reply]
thank u for replying vaia .
yes i did .
i uncommented it, and changed the last two fields
still getting error!
can there be any error because of CI version?
[Reply]
HI,
i jaust want to know how we receive email in codeigniter?
[Reply]
lavluda Reply:
March 3rd, 2010 at 11:29 am
@rajesh, check this http://codeigniter.com/wiki/imap_pop_class/
[Reply]
rajesh Reply:
March 3rd, 2010 at 2:55 pm
hi lavluda thnaks a ton.
[Reply]