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:
- 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