Although PHP provides the mail () function, but it does not work, and Phpmailer is a good mail delivery tool, it is very simple to use!
To send a message using Phpmailer :
Copy Code code as follows:
<?php
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; Open Certification
$mail->port = 25;
$mail->host = "smtp.163.com";
$mail->username = "phpddt1990@163.com";
$mail->password = "This is the password";
$mail->issendmail (); "Could not execute:/var/qmail/bin/sendmail" error message appears if no SendMail component is commented out
$mail->addreplyto ("phpddt1990@163.com", "McKee");/reply 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 = "$mail->altbody = "To view", compatible email viewer! with an HTML; Alternate display when the message does not support HTML, you can omit
$mail->wordwrap = 80; Set the length of each line of string
$mail->addattachment ("F:/test.png"); You can add attachments
$mail->ishtml (TRUE);
$mail->send ();
Echo ' message sent ';
catch (Phpmailerexception $e) {
echo "Mail send failed:". $e->errormessage ();
}
?>
Open my QQ Mail can see:
The test went very well:
As you can see from the above figure, Phpmailer is supported in HTML format, and it supports sending pictures, attachments! Tested for compatibility with a variety of SMTP servers!
Add an attachment if an error:
That's because (Set_magic_quotes_runtime ()) has been closed. And this attribute has been completely removed from the PHP6.
You can annotate or delete the wrong line, or precede the set_magic_quotes_runtime () with the @ sign
or configuration; error_reporting = E_all & ~e_notice & ~e_deprecated
Phpmailer and test file downloads: Phpmailer.rar