PHP mail (PHPMailer detailed introduction and instructions for use)
Source: Internet
Author: User
PHPMailer is also a powerful mail class PHPMailer main features: Support mail s/mime encrypted digital signatures support mail multiple TOs, CCs, BCCsandREPLY-TOs can work on any server platform, so you don't have to worry about the failure of the WIN platform to send emails... syntaxHighlig 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 ):
1. first download the latest package at http://phpmailer.worxware.com/
2. after the download is complete, find the class. phpmailer. php and class. smtp. php classes in your own directory!
3. 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.
$ 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 ('sender address, for example, admin # jiucool.com # Replace with @ ', '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!
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.