Main features and simple instructions of PHPMailer

Source: Internet
Author: User
This article mainly introduces the main features and simple instructions of PHPMailer. if you want to use PHPMailer, you can refer to it. I hope it will help you support mail s/mime-encrypted digital signatures.
Supports email to multiple TOs, CCs, BCCs and REPLY-TOs
Can work on any server platform, so you don't have to worry about the problem that Windows cannot send emails.
Supports text/HTML emails
Image embedding
The email client does not support HTML reading.
Powerful debugging for sending emails
Custom email header
Support for redundant SMTP servers
Supports 8-bit, base64, binary, and quoted-printable encoding.
Text wrap
Supports sending multiple attachments
Support for SMTP server verification
Tests on Sendmail, qmail, Postfix, Gmail, Imail, and Exchange platforms are successful.
The downloaded files include detailed instructions and examples, so you don't have to worry about getting started!
PHPMailer is very small, simple, convenient, and fast

PHPMailer usage (here we use gmail smtp to send emails as an example. of course, other methods such as sendmail pop are also supported ):
First download the latest package from
After the download is complete, find the class. phpmailer. php and class. smtp. php classes in your own directory!
Create a new php file named phpmail. php.
The content of phpmail. php is as follows:
I directly write the Mail sending module as a function postmail (). you can directly call this function when using it. the Function content is:

Program code

The code is as follows:

Function postmail ($ to, $ subject = "", $ body = ""){
// $ To indicates the recipient address $ subject indicates the Mail Title $ body indicates the mail body
// Error_reporting (E_ALL );
Error_reporting (E_STRICT );
Date_default_timezone_set ("Asia/Shanghai"); // Set the time zone UTC + 8.
Require_once ('class. phpmailer. php ');
Include ("class. smtp. php ");
$ Mail = new PHPMailer (); // A new PHPMailer object is displayed.
$ Body = eregi_replace ("[\]", '', $ body); // filter the email content.
$ Mail-> CharSet = "UTF-8"; // Set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise garbled
$ Mail-> IsSMTP (); // you can specify the SMTP service.
$ Mail-> SMTPDebug = 1; // enable the SMTP debugging function
// 1 = errors and messages
// 2 = messages only
$ Mail-> SMTPAuth = true; // enable SMTP verification
$ Mail-> SMTPSecure = "ssl"; // security protocol
$ Mail-> Host = ""; // SMTP server
$ Mail-> Port = 465; // SMTP server Port number
$ Mail-> Username = "SMTP server Username"; // SMTP server Username
$ Mail-> Password = "SMTP server Password"; // SMTP server Password
$ Mail-> SetFrom ('sender address, such as ', 'sender name ');
$ Mail-> AddReplyTo ("email reply address, such as", "email reply person name ");
$ Mail-> Subject = $ subject;
$ Mail-> AltBody = "To view the message, please use an HTML compatible email viewer! "; // Optional, comment out and test
$ Mail-> MsgHTML ($ body );
$ Address = $;
$ Mail-> AddAddress ($ address, "recipient name ");
// $ Mail-> AddAttachment ("images/phpmailer.gif"); // attachment
// $ Mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachment
If (! $ Mail-> Send ()){
Echo "Mailer Error:". $ mail-> ErrorInfo;
} Else {
Echo "Message sent! Congratulations, the email is sent successfully! ";

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.