Use PHPMailer to share the code for sending mails and use phpmailer to send mails

Source: Internet
Author: User

Use PHPMailer to share the code for sending mails and use phpmailer to send mails

Sending emails is a common function. LZ also encountered this feature in the project today.

First, download PHPMailer.

1. https://github.com/dwqs/PHPMailer

2. http://download.csdn.net/detail/u011043843/8063583

After the download, decompress the file to the corresponding location of the project directory and set the class. phpmailer. php and class. smtp. introduce php to the project and check the Code: (do not delete the decompressed file; otherwise, it will not work)

<? Php
// Import required
Require ("class. phpmailer. php ");
Require ("class. smtp. php ");
Date_default_timezone_set ('Asia/Shanghai'); // set the time zone UTC + 8.
$ Mail = new PHPMailer (); // create a mail sending class

$ Address = "15602277510@163.com ";
$ Mail-> IsSMTP (); // send using SMTP
$ Mail-> CharSet = "UTF-8"; // set the encoding, otherwise the Chinese Garbled text will be sent
$ Mail-> Host = "smtp.qq.com"; // your enterprise Post Office Domain Name
$ Mail-> SMTPAuth = true; // enable SMTP Verification
$ Mail-> Username = "461147874@qq.com"; // Post Office Username (enter the complete email address)
$ Mail-> Password = "***********"; // post office Password

$ Mail-> From = "461147874@qq.com"; // email address of the sender
$ Mail-> FromName = "dwqs ";
$ Mail-> AddAddress ($ address, "dwqs"); // The recipient address, which can be replaced with any email address in the format of AddAddress ("recipient email ", "Recipient Name ")
// $ Mail-> AddReplyTo ("","");

// $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // Add an attachment
// $ Mail-> IsHTML (true); // set email format to HTML // whether HTML format is used

$ Mail-> Subject = "verify email"; // mail title
$ Mail-> Body = "Hello, this is the test mail"; // The mail content
$ Mail-> AltBody = "This is the body in plain text for non-HTML mail clients"; // additional information, which can be omitted

If (! $ Mail-> Send ()){
Echo 'mailer Error: '. $ mail-> ErrorInfo;
} Else {
Echo "Message sent! Congratulations, the email is sent successfully! ";
}
?>

Test results:


(PHP) You can use PHPMailer to send emails successfully. I hope you can do the following:

1. Make a copy of the frequently used email login address data first.
2. determine the user's email service provider based on the user's email suffix
3. A prompt or jump is displayed on the webpage.

How does phpmailer send emails? -Technical Q &

After setting the PHPMAILer parameters, add the recipient step, right? Assume that your recipient list is stored in the array $ aMails: [php] $ mail ){? ? ? ? $ OMail-> SetAddress ($ mail) ;}$ oMailer-> Send () ;?> [/Php] However, it is recommended that you use Sendmail to send Group emails to avoid sending failures. Do not send too many emails each time to avoid timeout. You can use the paging principle for Batch Sending.
 

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.