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!