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.
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "xxx.yyy.zzz.aaa"; // SMTP server
$mail->From = "email@example.com";
$mail->FromName = "The Webmaster";
$mail->Subject = $subject;
$mail->Body = $pesan;
$mail->WordWrap = 50;
$info="Server email down. [" . $mail->ErrorInfo . "]";
$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.