Simple use of PHP mail class library PHPMailer

Source: Internet
Author: User

Recently, you need to use the mail sending function, which was originally sent using the mail () function provided by PHP. Php mail () is a simple, convenient, and easy-to-use method. However, in addition to Netease mailbox, QQ mailbox, GMAIL mailbox, and other frequently used mailboxes, it has been tested that HOTMAIL, TOM, LIVE and other mailboxes cannot receive such emails. Therefore, PHPMailer is the powerful mail sending class.

Some examples provided by the official website may report Mailer Error: cocould not instantiate mail function. After referring to some materials, I wrote a method myself. The code is very simple and I will not explain it much.

Function mailto ($ nickname, $ address, $ id, $ activation_code) {date_default_timezone_set ('prc'); include_once ("class. phpmailer. php "); $ mail = new PHPMailer (); // defaults to using php" mail () "$ mail-> IsSMTP (); $ mail-> Host = "smtp.163.com"; // SMTP server $ mail-> SMTPAuth = true; // open SMTP authentication $ mail-> Username = "bkjia@163.com "; // username $ mail-> Password = "yourpassword"; // Password // $ body = file_get_contents ('applicati On/views/nmra/register.html '); // $ body = preg_replace ('/\\\\/', '', $ body ); // Strip backslashes $ body = '<p> <body style = "margin: 10px;"> </p>'; $ body. = '<div style = "width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">'; $ body. = '<div align = "center">  </div>'; $ body. = '<p> '. $ nickname. ', hello. </P> '; $ body. =' <p> congratulations, you have become a member of the '. $ id.' Research Association of the house of friends. </P> '; $ body. = '<p> bangke Research Association is a community where programmers, siege lions, design lions, and developers exchange and discuss topics. I hope you can find topics of interest and like-minded friends here. </P> '; $ body. =' Please click the following link to verify your mailbox, please note that the domain name is bkjia.com: <a href = "http://www.bkjia.com/librarys/accounts/activation? Code = "'. $ activation_code.'" target = "_ blank"> http://www.bkjia.com/librarys/accounts/activation? Code = '. $ activation_code.' </a> '; $ body. =' <p> I wish you a pleasant job and a pleasant life. </P> '; $ body. = '</div> </body>'; // echo $ body; $ mail-> AddReplyTo ("bkjia@163.com", "Gonn "); $ mail-> SetFrom ('bkjia @ 163.com ', 'gonn'); $ mail-> AddReplyTo ("bkjia@163.com", "Gonn"); $ address = "252211974@qq.com "; // $ address = "bkjia@gmail.com"; $ mail-> AddAddress ($ address, $ nickname); $ subject = "receive email from the customer's house "; $ mail-> Subject = "=? UTF-8? B? ". Base64_encode ($ subject )."? = "; // Optional, comment out and test $ mail-> AltBody =" To view the message, please use an HTML compatible email viewer! "; $ Mail-> MsgHTML ($ body); // $ mail-> AddAttachment (" images/phpmailer.gif "); // attachment // $ mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachmentif (! $ Mail-> Send () {// echo "Mailer Error:". $ mail-> ErrorInfo;} else {// echo "Message sent! ";}}

When using PHP, you only need to introduce two PHP classes, and then write a method by yourself. The two classes are very small and the mail sending speed is fast.

PHPMailer is a powerful mail class with its main features:

  1. Supports mail s/mime-encrypted digital signatures
  2. Supports email to multiple TOs, CCs, BCCs and REPLY-TOs
  3. Can work on any server platform, so you don't have to worry about the problem that Windows cannot send emails.
  4. Supports text/HTML emails
  5. Image embedding
  6. The email client does not support HTML reading.
  7. Powerful debugging for sending emails
  8. Custom Email header
  9. Support for redundant SMTP servers
  10. Supports 8-bit, base64, binary, and quoted-printable encoding.
  11. Text wrap
  12. Supports sending multiple attachments
  13. Support for SMTP server Verification
  14. Tests on Sendmail, qmail, Postfix, Gmail, Imail, and Exchange platforms are successful.
  15. The downloaded files include detailed instructions and examples, so you don't have to worry about getting started!
  16. PHPMailer is very small, simple, convenient, and fast

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.