Using the PHPMailer library to send html emails using a SMTP server
This is a beginner tutorial on how to create a script to send out html emails using the PHPMailer library. This will be a very simple script, we will edit the mail in the actually code and run that PHP page to send out the mail. At a later stage I will include a tutorial on how to implement a WYSIWYG editor such as FCKEditor. Firstly, what is the PHPMailer library? PHPMailer is a fully featured email transfer class for PHP. It has the following features: send emails with multiple TOs, CCs, BCCs and REPLY-TOs; SMTP support; alternative/plain text sending; word wrap; debugging features; attachment and imbedded image support.
Ok, now we need the PHPMailer library, it is free so don’t worry! You can get it from here: http://phpmailer.codeworxtech.com/ just click on the download tab at the top of the screen.
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();$mail->Host = "smtp1.domain.com”;
$mail->SMTPAuth = true;
$mail->Username = "username";$mail->Password = "password";
$mail->From = "from@domain.com";
$mail->FromName = "Domain.com";
$mail->AddAddress("sendto@email.com");
$mail->AddReplyTo("info@domain.com");
$mail->WordWrap = 50;$mail->IsHTML(true);
$mail->Subject = "Your subject";
$mail->Body = " This is a test";
$mail->AltBody = "plain text message";
if(!$mail->Send()){ echo "Message could not be sent. ";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;}
echo "Message has been sent";?>
Posted in General Opensource