PHP simple way to use Phpmailer to send mail _php tutorials

Source: Internet
Author: User
Tags word wrap
Recently, the ability to send mail was sent using the mail () function from PHP. PHP mail () This method is very simple, convenient, easy to use, but in addition to NetEase mailbox, QQ mailbox, Gmail mailbox and other commonly used mailboxes can be received, after testing Hotmail, TOM, live and other mailboxes are not receiving such mail. So instead of using Phpmailer, this powerful mail-sending class.
Some examples of the use of the official band, some will be reported Mailer error:could not instantiate mail function. This error. After referencing some information, I wrote a method. The code is simple enough to explain.
Copy CodeThe 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; Turn on 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 on becoming the "$id." Member of the Concise Institute of Modern Magic Research.

';
$body. = '

The Institute of Modern Magic Studies (Nowamagic Research Association) is a community of program apes, siege lions, design lions and developers for technical exchanges and topic discussions. Hopefully here you can find topics of interest with like-minded friends.

';
$body. = ' Please click on the link below to verify your email address, 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 work and a comfortable 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 mail 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!";
}
}

As long as the use of the introduction of two PHP classes, and then write their own method is OK, two classes are small, send mail fast.
Phpmailer is a powerful message class with its main functional features:
Digital signatures that support message S/MIME encryption
Support mail multiple TOs, CCs, BCCs and Reply-tos
Can work on any server platform, so don't worry about the win platform can't send mail the problem
Supports text/html format messages
Image images can be embedded
Support for HTML reading is not supported for mail clients
Powerful debug function for sending mail
Custom Mail Header
Redundant SMTP server support
Supports 8bit, base64, binary, and quoted-printable codes
Word Wrap
Support multi-attachment sending function
Support for SMTP server Authentication feature
Tested successfully on SendMail, QMail, Postfix, Gmail, Imail, and Exchange platforms
The download file provided includes a detailed description of the contents of the document and

http://www.bkjia.com/PHPjc/825136.html www.bkjia.com true http://www.bkjia.com/PHPjc/825136.html techarticle recently, the ability to send mail was sent using the mail () function from PHP. PHP mail () This method is very simple, convenient, easy to use, but in addition to NetEase mailbox, QQ mailbox 、...

  • Related Article

    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.