How to use PHPMailer to send emails. PHPMailer is a powerful Mail sending class written in PHP. it can be used to send mails more conveniently and send attachments and HTML emails, at the same time, you can use SMTP server PHPMailer as a powerful Mail sending class written in PHP. it can be used to send emails more conveniently and send attachments and HTML emails, you can also use the SMTP server to send emails.
You may ask, isn't PHP already built into the mail () function? why is PHPMailer used? The mail () function is not fully functional. it can only send text emails and mail () the function can only be used on Linux servers (this is why many WP blog users installed on Windows hosts cannot receive emails after registration). another major problem is the use of mail () the function does not verify the identity of emails sent. many emails cannot receive emails sent using the mail () function or directly enter the spam mailbox.
Main PHPMailer functions
The email contains multiple TO, CC, BCC, and REPLY-.
The platform is widely used. supported SMTP servers include Sendmail, qmail, Postfix, Gmail, Imail, and Exchange.
Supports embedding images, attachments, and HTML emails.
Reliable and powerful debugging functions.
Supports SMTP Authentication.
Customize the mail header.
8-bit, base64, binary, and quoted-printable encoding are supported.
Simple use of PHPMailer
Here we will introduce the most common Gmail.
Copy to ClipboardReference: [www.bkjia.com] require_once ('class. phpmailer. php ');
Require_once ("class. smtp. php ");
$ Mail = new PHPMailer ();
$ Mail-> CharSet = "UTF-8"; // sets the mail encoding, the default ISO-8859-1, which must be set to UTF-8 if you send Chinese
$ Mail-> IsSMTP (); // you can specify the SMTP service.
$ Mail-> SMTPAuth = true; // enable SMTP verification
$ Mail-> SMTPSecure = "ssl"; // SMTP Security Protocol
$ Mail-> Host = "smtp.gmail.com"; // SMTP server
$ Mail-> Port = 465; // SMTP server Port number
$ Mail-> Username = "your_name@gmail.com"; // SMTP server Username
$ Mail-> Password = "your_password"; // SMTP server Password
$ Mail-> SetFrom ('sender address', 'sender name'); // you can specify the sender address and name.
$ Mail-> AddReplyTo ("email reply to address", "email reply to name ");
// Set the email reply recipient's address and name
$ Mail-> Subject = ''; // you can specify the mail title.
$ Mail-> AltBody = "to view this email, switch to an HTML-supported email client ";
// Optional, backward compatibility considerations
$ Mail-> MsgHTML (''); // you can specify the email content.
$ Mail-> AddAddress ('recipient address', "recipient name ");
// $ Mail-> AddAttachment ("images/phpmailer.gif"); // attachment
If (! $ Mail-> Send ()){
Echo "failed to send:". $ mail-> ErrorInfo;
} Else {
Echo "congratulations, the email is sent successfully! ";
}
Download: PHPMailerIf you are a WordPress user, you do not need to download it. WordPress already comes with PHPMailer.
Http://www.bkjia.com/PHPjc/363793.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/363793.htmlTechArticlePHPMailer is a powerful PHP-compiled mail class, which can be used to send mail more conveniently, and can also send attachments and HTML-format mail, you can also use the SMTP server...