PHP use Phpmailer to send messages using a simple method _php instance

Source: Internet
Author: User
The recent need to use the function of sending mail, originally from the PHP with the Mail () function sent. 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 mailbox can receive, tested Hotmail, TOM, live and other mailboxes are not received such mail. So instead of using Phpmailer, this powerful mail-sending class.
Using some examples from the official band, some will report Mailer error:could not instantiate mail function. This error. After reference to some information, or write a method of their own. The code is simple enough to explain it.
Copy Code code 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 = ' <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 on being a member of the Concise Modern Magical Research Association, the first $id. </p> ';
$body. = ' <p> The association of Modern Magical Studies (Nowamagic Research Association) is a community of program apes, siege lions, design lions and developers on technical exchanges and topic discussions. Hopefully here you can find interesting topics with like-minded friends. </p> ';
$body. = ' Please click the link below to verify your email, please note that the domain name is nowamagic.net:<a href= "http://www.nowamagic.net/librarys/accounts/activation/? Code= "'. $activation _code. '" target= "_blank" >http://www.nowamagic.net/librarys/accounts/activation/?code= ". $ Activation_code. ' </a> ';
$body. = ' <p> Shun wish work study happy, life is comfortable. </p> ';
$body. = ' </div></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 = "Received from the Concise Modern Magic Mail";
$mail->subject = "=? UTF-8? B? ". Base64_encode ($subject). "? =";
Optional, comment out and test
$mail->altbody = "To view", compatible email viewer! with an HTML;
$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!";
}
}

The use of the time as long as the introduction of two PHP classes, and then write a method on their own OK, two classes are very small, send mail speed is also very fast.
Phpmailer is a powerful message class, its main 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 not send mail problems
Support Text/html format mail
Can embed image images
Support for mail clients that do not support HTML reading
Powerful Send-mail debugging features debug
Customizing message headers
Redundant SMTP server support
Supports 8bit, base64, binary, and quoted-printable encodings
Text Wrap
Support multiple attachment send function
Supports the SMTP server Authentication feature
Platform test success in SendMail, QMail, Postfix, Gmail, Imail, Exchange, etc.
Provided in the download file, including a detailed description of the document and the following

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.