PHPMailer sends an email

Source: Internet
Author: User
Tags php email

I just published my blog post to share with you ^ _ ^. The following post reposts my blog: JIU Ku blog
In the previous article, some mailboxes in the PHP mail () method cannot receive emails. The following describes phpmailer, a free and open-source php email program. Let's take a look at it, all of the following materials are from the official phpmailer Website:

PHPMailer is also a powerful mail class

Main features of PHPMailer:

Supports 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
The above materials are translated by Jiucool from the phpmailer official website. For more information, see!

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 go to http://phpmailer.worxware.com/download the latest version of the package
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_jiucool.php.
Phpmail_jiucool.php contains the following content:
I directly write the mail sending module as a function postmail_jiucool_com (). You can directly call this function when using it. The function content is:
Function postmail_jiucool_com ($ to, $ subject = "", $ body = ""){
// Author: Jiucool WebSite: http://www.jiucool.com
// $ 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 as necessary.
$ 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.googlemail.com"; // 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 (the sender address, for example, admin # jiucool.com # is replaced with @, and the sender name );
$ Mail-> AddReplyTo ("email reply address, such as admin # jiucool.com # changed to @", "email reply Recipient Name ");
$ Mail-> Subject = $ subject;
$ Mail-> AltBody = "To view the message, please use an HTML compatible email viewer! -From www.jiucool.com "; // 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! ";
}
}
Of course there are more and more detailed configuration methods that you can use freely!

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.