Although PHP provides the mail () function, but it does not work well, and Phpmailer is a good mail sending tool, the use of it is very simple!
To send a message using Phpmailer :
Copy the Code code as follows:
Header ("Content-type:text/html;charset=utf-8");
Ini_set ("Magic_quotes_runtime", 0);
Require ' class.phpmailer.php ';
try {
$mail = new Phpmailer (true);
$mail->issmtp ();
$mail->charset= ' UTF-8 '; Set the character encoding of the message, which is important, otherwise Chinese garbled
$mail->smtpauth = true; Turn on authentication
$mail->port = 25;
$mail->host = "smtp.163.com";
$mail->username = "phpddt1990@163.com";
$mail->password = "This is the password";
$mail->issendmail (); If no SendMail component is commented out, "Could not execute:/var/qmail/bin/sendmail" error message appears
$mail->addreplyto ("phpddt1990@163.com", "McKee");//Reply to address
$mail->from = "phpddt1990@163.com";
$mail->fromname = "www.phpddt.com";
$to = "987044391@qq.com";
$mail->addaddress ($to);
$mail->subject = "Phpmailer test title";
$mail->body = "
Phpmail Demo
This is the PHP point-and-click (www.phpddt.com) to phpmailer test content ";
$mail->altbody = "To view the message, please use an HTML compatible email viewer!"; Alternate display when the message does not support HTML, you can omit
$mail->wordwrap = 80; Set the length of a string per line
$mail->addattachment ("F:/test.png"); can add attachments
$mail->ishtml (TRUE);
$mail->send ();
Echo ' Mail has been sent ';
} catch (Phpmailerexception $e) {
echo "Message sent failed:". $e->errormessage ();
}
?>
Open my QQ mail to see:
The test went very well:
As can be seen, Phpmailer is supported in HTML format, and supports sending pictures, attachments! Tested, compatible with all kinds of SMTP servers!
Add Attachment if error:
That's because (Set_magic_quotes_runtime ()) has been closed. This feature has been completely removed from the PHP6.
You can comment or delete the line that went wrong, or add the @ sign before set_magic_quotes_runtime ()
or configuration; error_reporting = E_all & ~e_notice & ~e_deprecated
Phpmailer and test file download: Phpmailer.rar
http://www.bkjia.com/PHPjc/326254.html www.bkjia.com true http://www.bkjia.com/PHPjc/326254.html techarticle Although PHP provides the mail () function, but it does not work well, and Phpmailer is a good mail sending tool, the use of it is very simple! Send mail using phpmailer: Copy code ...