PHP How To Send HTML Email with SMTP Authentication
Posted by tech on
April 28, 2008
Here’s a code snippet on how to send HTML email with SMTP authentication using PHP. You would have to download a library called PHPMailer as the mail() function of PHP does not support SMTP authentication. There is also other class that must be in the same location as class.phpmailer.php in order for the mail sending to work, smtp.phpmailer.php.
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$mail->Username = "username"; // your SMTP username
$mail->Password = "password"; // your SMTP password
$mail->Host = "smtp.host.url"; // SMTP server
$mail->From = $from;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}











October 1st, 2008 at 3:23 am
You might also want to try the mMail library found here:
http://www.virtualthinking.com/loadhtml.php?where=scripts&what=art_show.php&db_target=00000000023
October 1st, 2008 at 7:05 pm
cool, ill check that one out. thanks
September 5th, 2009 at 12:19 am
But where will I get the “class.phpmailer.php”
September 5th, 2009 at 9:22 am
you can google it kamal. there should easily be lots of results for it.
April 11th, 2010 at 5:57 pm
Very good blog post, this is very similar to a site that I have. Please check it out sometime and feel free to leave me a comenet on it and tell me what you think. Im always looking for feedback.