Use PHPMailer to share email sending code. phpmailer mail _ PHP Tutorial

Source: Internet
Author: User
Use PHPMailer to share the code of sending mails, and use phpmailer to send mails. PHPMailer is used to share the Mail sending code. phpmailer is a common function for sending mails. LZ also encountered this feature in the project today. First, download PH and use PHPMailer to share the Mail sending code.

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

First, download PHPMailer.



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 = " ";
$ Mail-> IsSMTP (); // send using SMTP
$ Mail-> CharSet = "UTF-8"; // Set the encoding, otherwise the Chinese garbled text will be sent
$ Mail-> Host = ""; // your enterprise Post Office domain name
$ Mail-> SMTPAuth = true; // enable SMTP verification
$ Mail-> Username = ""; // Post Office Username (enter the complete email address)
$ Mail-> Password = "***********"; // Post Office Password

$ Mail-> From = ""; // 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.

The frequently-used function of sending emails to the consumer is introduced by LZ in the project today. First, download PH...

Related Article

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: 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.