Phpmailer uses 163 mail to send an example. phpmailer163_PHP tutorial

Source: Internet
Author: User
Tags word wrap
Phpmailer uses phpmailer163 as an example to send a 163 email. Phpmailer uses 163 mail to send emails. phpmailer163 note: If your server is installed with the maximum anti-virus function for selling coffee and opening an account, disable email protection. phpmailer uses 163 mail to send emails, 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

TIPS note: If your server has the biggest protection function for selling coffee and opening an account, we need to disable email protection ,...

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.