Phpmailer uses 163 mail to send emails-PHP source code

Source: Internet
Author: User
Tags php email word wrap
Phpmailer is a free php email sending plug-in. We can use phpmailer to log on to the specified email and then use this email to send an automatic email to us. Now, the free email is like 163, sina supports all of them, but sina needs to simply open the pop3 coroutine. If you have a good time, let's take a look at the phpmainer163 email to send an email. Phpmailer is a free php email sending plug-in. We can use phpmailer to log on to the specified email and then use this email to send an automatic email to us. Now, the free email is like 163, sina supports all of them, but sina needs to simply open the pop3 coroutine. If you have a good time, let's take a look at a phpmainer 163 email to send an email.

Script ec (2); script

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 ");
// 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.

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.