Using PHPMailer to send emails

I have the need on one of my sites to send emails after generating results from a questionnaire.  I came across phpmailer and really liked it, it has some great functionality and is pretty easy to setup.

Here is a code example:

$eMail = "[email protected];
$message = "This is my email message";
require 'PHPMailer/class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
// Set PHPMailer to use the sendmail transport
$mail->IsSMTP();
//Set who the message is to be sent from
$mail->SetFrom('[email protected]', 'John Smith');
//Set who the message is to be sent to
$mail->AddAddress($eMail);
//Set the subject line
$mail->Subject = 'this is my subject';
//HTML message body, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
$mail->MsgHTML(htmlspecialchars_decode($message), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is the plain text portion of the email.';
//Attach an image file
$mail->AddAttachment($pdffile);
//Send Email
$mail->send();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.