PHPMailer: Other Way to Send Email from PHP
What will you do if you have to create an auto email responder in a web application but it hosted on a web server with no local SMTP port opened? Try this tiny module called PHPMailer. With PHPMailer, there are no problem to make any interactive email responder over your web application but – in a condition - you need to provide access to any available SMTP server. Guess what? No big deal about the un-existing SMTP server since there are tons free of it spread over the internet. Just let the uncle Google searched it for you. This article are based on my very own experiences to build yet another Customer Relationship Management (CRM) module upon my web corporate.
First, download the packages from http://phpmailer.sourceforge.net/ and put 3 main files (class.phpmailer.php, phpmailer.lang-en.php & class.smtp.php) into a directory you have specified before (for example: /phpmailer). Next, create a single initialization email function just right below likes all the way you do in a built-in SMTP server web hosting (this is a modification of examples provided by PHPMailer):
In other situation, you might meet another error message likes "Language string failed to load". This is a weird condition for me since there are seem no mistakes over my own PHP source. A short command string below is the answer:
Sounds good enough? No? Well, the
First, download the packages from http://phpmailer.sourceforge.net/ and put 3 main files (class.phpmailer.php, phpmailer.lang-en.php & class.smtp.php) into a directory you have specified before (for example: /phpmailer). Next, create a single initialization email function just right below likes all the way you do in a built-in SMTP server web hosting (this is a modification of examples provided by PHPMailer):
require("lib/class.phpmailer.php");For some reason, some times you will facing an error message likes "SMTP Error: The following recipients failed [myemail@mydomain]". This error usually occurs because relaying is not allowed on the SMTP server from the IP address of the web server. Go to the configuration of your SMTP server and turn relaying on for your IP address and try again.
require("lib/phpmailer.lang-en.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "xxx.yyy.zzz.aaa"; // SMTP server
$mail->From = "you@domain.com";
$mail->FromName = "The Webmaster";
$mail->IsHTML(true);
$mail->SetLanguage("en", "phpmailer/");
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $pesan;
$mail->WordWrap = 50;
if(!$mail->Send())
{
$info="Server email down. [" . $mail->ErrorInfo . "]";
}
else
{
$info="Respon telah dikirim ke alamat $email.";
}
In other situation, you might meet another error message likes "Language string failed to load". This is a weird condition for me since there are seem no mistakes over my own PHP source. A short command string below is the answer:
$mail->SetLanguage("en", "./phpmailer/");Where phpmailer is the subdirectory containing the language file.
Sounds good enough? No? Well, the
$mail->IsHTML(true);command, enable you to send an HTML email format. Just create the HTML syntax from common HTML editor. I usually using Macromedia Dreamweaver to make a full HTML syntax. Copy all the HTML source into the $email variable and mixed it with another resources such database or images to make some improvements. Sounds good enough now?
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Anonymous said,
Thursday, November 20, 2008 6:07:00 AM
Excellent Post
Keep up the Good Work!
Aldo said,
Wednesday, March 30, 2011 2:45:00 PM
thanks you save me from this problem "SMTP Error: The following recipients failed [myemail@mydomain]". This error usually occurs because relaying is not allowed on the SMTP server from the IP address of the web server. Go to the configuration of your SMTP server and turn relaying on for your IP address and try again.
Web Hosting India said,
Thursday, August 01, 2013 10:02:00 PM
I know php mailer but there is a problem with my web host, they don't allow more than 200 email / hr. What should I do and with track code I got to know that most of my mails are going to spam box. What to do.
Unknown said,
Friday, August 02, 2013 3:47:00 PM
Hi Web Hosting India,
I used to had the same problem, but what I did was creating more than one account so I could transmit messages content sequentially to other accounts if previous account has failed to send (this is indicating that previous account might be over quota :)
Good luck!