PHP simple use of PHPMailer to send mail _ php instance

Source: Internet
Author: User
This article is a simple method for PHP to use PHPMailer to send mails. It provides code written by PHP and needs to use the mail sending function recently. it 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. = 'Please click the following link to verify your mailbox, please note that the domain name is nowamagic.net: http://www.nowamagic.net/librarys/accounts/activation? 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.