Phpmailer details on sending gmail mail instances

Source: Internet
Author: User
Tags gmail mail gmail password
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! ";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.