PHP uses the Gmail sending capability of the PHPMailer component to send emails

Source: Internet
Author: User
Tags gmail password

System Environment: windows7 + wamp5

Environment requirements: Gmail account + open_ssl + PHPMailer;

1. Open_ssl is not enabled for wamp5 by default. You need to modify php. ini and remove the semicolon before extension = php_openssl.dll;

2. Download PHPMailer,

PHPMailer is a class written in PHP for sending mails. You can download the latest version of PHPMailer_v5.0.2.

3. decompress the package to the server, open the examples file, and then create a PHP tutorial file (just name it yourself) in the simple example folder ), generation:

// If you want to publish this article, please indicate the exit, no outgoing copyright notice, I do not like to see this kind of website. My work website does not indicate the person who is serving Seven {See7di # Gmail.com}

<? Php
// Error_reporting (E_ALL );
Error_reporting (E_STRICT );
Date_default_timezone_set ('America/Toronto ');
Require_once ('../class. phpmailer. php ');
// Include ("class. smtp. php"); // optional, automatically loaded from class. phpmailer. php
$ Mail = new PHPMailer ();
Using bodypolicfile_get_contents('contents.html ');
$ Body = Strtr ($ body, Array ("\" => ""); // $ body = eregi_replace ("[\]", '', $ body );
$ Mail-> IsSMTP (); // tells the program to use SMTP
$ Mail-> SMTPDebug = 2; // enable SMTP debug information (used during testing) // 1 = Error and message // 2 = only message
$ Mail-> SMTPAuth = true; // enable SMTP Verification
$ 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 = "see7di@gmail.com"; // GMAIL Username
$ Mail-> Password = "******"; // GMAIL Password
$ Mail-> CharSet = "UTF-8"; // you can add this line of code to prevent Garbled text.

$ Mail-> SetFrom ('see7di @ gmail.com ', 'zhang san'); // the sender's email address and User Name
// $ Mail-> AddReplyTo ("see7di@gmail.com", "Zhang San"); // reply address and User Name

$ Subject = 'this is the subject of imports ';
$ Mail-> Subject = "=? UTF-8? B? ". Base64_encode ($ subject )."? = "; // Base64 encoding is used to prevent garbled characters in the letter title

$ Mail-> MsgHTML ($ body );

$ Mail-> AddAddress ("see7di@msn.com", "Li Si"); // recipient email address and User Name
// Attachment
// $ 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! ";
}
?>

OK!

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.