Phpmailer uses the 163 email sending example, phpmailer163
NOTE: If your server has the biggest anti-virus feature for selling coffee and opening an account, we need to disable email protection. Otherwise, your email cannot be sent out to be blocked by this anti-virus service.
1. Use scripts sent by gmail
The Code is as follows:
Include ("class. phpmailer. php ");
Include ("class. smtp. php ");
// Obtain the content of an external file
$ Mail = new PHPMailer ();
$ Body = file_get_contents('contents.html ');
$ Body = eregi_replace ("[]", '', $ body );
// Set smtp Parameters
$ Mail-> IsSMTP ();
$ Mail-> SMTPAuth = true;
$ Mail-> SMTPKeepAlive = true;
$ Mail-> SMTPSecure = "ssl ";
$ Mail-> Host = "smtp.gmail.com ";
$ Mail-> Port = 465;
// Enter your gmail account and password
$ Mail-> Username = "yourname@gmail.com ";
$ Mail-> Password = "password ";
// Set the sender. It is best not to counterfeit the address.
$ Mail-> From = "yourname@gmail.com ";
$ Mail-> FromName = "Webmaster ";
$ Mail-> Subject = "This is the subject ";
$ Mail-> AltBody = $ body;
$ Mail-> WordWrap = 50; // set word wrap
$ Mail-> MsgHTML ($ body );
// Set the reply address
$ Mail-> AddReplyTo ("yourname@gmail.com", "Webmaster" (www.111cn.net ));
// Add an attachment. The attachment and script are in the same directory.
// Otherwise, enter the complete path
$ Mail-> AddAttachment ("attachment.jpg ");
$ Mail-> AddAttachment ("attachment.zip ");
// Set the email address and name of the email recipient
$ Mail-> AddAddress ("toname@gmail.com", "FirstName LastName ");
// Send emails in HTML Format
$ Mail-> IsHTML (true );
// Send an email using the Send Method
// Process the data according to the sending result
If (! $ Mail-> Send ()){
Echo "Mailer Error:". $ mail-> ErrorInfo;
} Else {
Echo "Message has been sent ";
}
2. Use the 163 email sending script
You only need to change the SMTP configuration and account password. The SMTP configuration is as follows:
The Code is as follows:
// Set smtp Parameters
// Note that the ssl protocol is not required here
$ Mail-> IsSMTP ();
$ Mail-> SMTPAuth = true;
$ Mail-> SMTPKeepAlive = true;
$ Mail-> Host = "smtp.163.com ";
$ Mail-> Port = 25;
If the test passes in the local wampserver environment, you must enable the php_openssl extension.
Experience Sharing
Some friends refer to this tutorial to use sina mail to log on and send emails. You find that sina mail does not support this function, in fact, this is not because Sina mail does not support this function. We need to open the pop3 protocol in Sina mail. The method for opening an account is to log on to Sina, we have a setting button next to more on the right side, after clicking enter, we will see that there is an "account setting", and then there is a pop3 co-definition class at the bottom, we can open an account, in this way, you can try the above Code to solve the problem. Why do you not need to set the 163 email in a friend's department? Because 163 emails enable pop3 by default.
From: http://www.111cn.net/phper/php-cy/61846.htm
In windows2003, when phpmailer is used to send a 163 email, the system prompts "cocould not connect to SMTP host ".
You can telnet SMTP host 25 on Windows 2003 to see if it is successful.
163 SMTP should be smtp.163.com, depending on your defined value.
Telnet smtp.163.com 25
Phpmailer sent 163 of the mail, Chinese is garbled, into what utl-8 and gbk are useless, solution?
Note the PHP file encoding.
Set the encoding when sending the message.
Date_default_timezone_set ("Asia/Shanghai"); // set the time zone UTC + 8.
$ Mail-> CharSet = "UTF-8"; // sets the mail encoding, the default ISO-8859-1, which must be set if the Chinese character is sent