This article provides a detailed analysis of the gmail mail instance sent by phpmailer. For more information, see
The code is as follows:
PHPMailer-SMTP (Gmail) basic test
// Error_reporting (E_ALL );
Error_reporting (E_STRICT );
Date_default_timezone_set ('America/Toronto ');
Require_once ('../class. phpmailer. php ');
// Include ("class. smtp. php"); // optional, gets called from within class. phpmailer. php if not already loaded
$ Mail = new PHPMailer ();
$ Body = file_get_contents('contents.html ');
$ Body = eregi_replace ("[\]", '', $ body );
$ Mail-> IsSMTP (); // telling the class to use SMTP
$ Mail-> Host = "mail.gmail.com"; // SMTP server
$ Mail-> SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$ Mail-> SMTPAuth = true; // enable SMTP authentication
$ Mail-> SMTPSecure = "ssl"; // sets the prefix to the servier
$ Mail-> Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$ Mail-> Port = 465; // set the SMTP port for the GMAIL server
$ Mail-> Username = "*** @ gmail.com"; // GMAIL username
$ Mail-> Password = "***"; // GMAIL password
$ Mail-> SetFrom ('***** @ gmail.com', 'First last ');
$ Mail-> AddReplyTo ("*** @ gmail.com", "First Last ");
$ Mail-> Subject = "PHPMailer Test Subject via smtp (Gmail), basic ";
$ Mail-> AltBody = "To view the message, please use an HTML compatible email viewer! "; // Optional, comment out and test
$ Mail-> MsgHTML ($ body );
$ Address = "*** @ gmail.com ";
$ Mail-> AddAddress ($ address, "John Doe ");
$ Mail-> AddAttachment ("images/phpmailer.gif"); // attachment
$ Mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachment
If (! $ Mail-> Send ()){
Echo "Mailer Error:". $ mail-> ErrorInfo;
} Else {
Echo "Message sent! ";
}
?>