PHP simple use of PHPMailer to send emails

Source: Internet
Author: User
This article is a simple method for PHP to use PHPMailer to send emails. It provides code written by itself.

This article is a simple method for PHP to use PHPMailer to send emails. It provides code written by itself.

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.

The Code is as follows:


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; // enable SMTP authentication
$ Mail-> Username = "nowamagic@163.com"; // User Name
$ Mail-> Password = "yourpassword"; // Password

// $ Body = file_get_contents ('application/views/nmra/register.html ');
// $ Body = preg_replace ('// \\\/', '', $ body); // Strip backslashes
$ Body ='

';
$ Body. ='

';
$ Body. ='

';
$ Body. ='

'. $ Nickname.', hello.

';
$ Body. ='

Congratulations! You have become the name'. $ id. 'Member of the concise modern magic Research Association.

';
$ Body. ='

The modern magic Research Association (NowaMagic Research Association) is a community where programmers, siege lions, design lions, and developers discuss and discuss technology. I hope you can find topics of interest and like-minded friends here.

';
$ Body. = 'click the following link to verify your email address. Note that the domain name is nowamagic.net :? Code = '. $ activation_code .'';
$ Body. ='

I wish you a pleasant job and a pleasant life.

';
$ Body. ='

';
// Echo $ body;
$ Mail-> AddReplyTo ("nowamagic@163.com", "Gonn ");
$ Mail-> SetFrom ('nowamagic @ 163.com ', 'gonn ');
$ Mail-> AddReplyTo ("nowamagic@163.com", "Gonn ");
$ Address = "252211974@qq.com ";
// $ Address = "nowamagic@gmail.com ";
$ Mail-> AddAddress ($ address, $ nickname );

$ Subject = "receive email from concise modern magic ";
$ 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"); // attachment

If (! $ 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 instructions.

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.