PHPMailer: Other Way to Send Email from PHP
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. |
Thursday, November 20, 2008 6:07:00 AM
Excellent Post
Keep up the Good Work!
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.
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.
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!