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 (systemplugins) 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 = "[email protected]"; // GMAIL username
$mail->Password = "xxxxxx"; // GMAIL password
*/
$mail->From = "[email protected]";
$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("[email protected]");
$mail->AddReplyTo("[email protected]","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";
}
}
}
?>
Categories: My Works, PHP, Programming Help ci, codeigniter, mail, PHP, php5, phpmailer, Programming
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?
looks like your mail server don’t need ssl, so just comment it . 🙂
I am getting this error vaia
can u help me out here?
“Mailer Error: SMTP Error: Could not connect to SMTP host.”
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.
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 🙂
It doesn’t work me bro
can you help me?
“Mailer Error: SMTP Error: Could not connect to SMTP host.â€
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 = “[email protected]”; // GMAIL username
$mail->Password = “xxxxxx”; “
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?
HI,
i jaust want to know how we receive email in codeigniter?
@rajesh, check this http://codeigniter.com/wiki/imap_pop_class/
hi lavluda thnaks a ton.
Great Work! Thanks for posting. It really helped me. Thanks a lot!
nice post.
but when i tried on my application, it’s still not send anything to yahoo account.
no meesage sent on yahoo account…
do you know what the problem??
thanks…
Worked immediately with gmail, thanks for the post… so much easier than trying to install sendmail… etc
HI i m not reciving mails to my hotmail id can any body help me its working for gmail and yahoo but not for hotmail
Thanks