Although php provides the mail() function, it is not easy to use. PHPMailer is a good email sending tool and is very simple to use!
Use PHPMailer to send emails:
Copy the code The code is 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 email, this It is very important, otherwise the Chinese characters will be garbled
$mail->SMTPAuth = true; //Enable authentication
$mail->Port = 25;
$mail->Host = "smtp.163.com ";
$mail->Username = "phpddt1990@163.com";
$mail->Password = "This is the password";
//$mail->IsSendmail(); //If there is no sendmail component, comment it out, otherwise the error message "Could not execute: /var/qmail/bin/sendmail" will appear
$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 = "
This is the test content of phpmailer by php diandiantong (www.phpddt.com)";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //Alternate display when the email does not support HTML, you can omit it
$mail->WordWrap = 80; //Set the length of each line of string
//$mail->AddAttachment("f:/test.png"); //Attachments can be added
$mail->IsHTML(true);
$mail->Send();
echo 'Email has been sent';
} catch (phpmailerException $e) {
echo "Failed to send email:".$e->errorMessage();
}
?> ;
Open my qq mail and you can see:
The test went very smoothly:
As you can see from the picture above, PHPMailer supports sending in html format, and also supports sending pictures and attachments! After testing, it is very compatible with various SMTP servers!
If an error is reported when adding attachments:
That’s because (set_magic_quotes_runtime()) has been turned off. And this feature has been completely removed in PHP6.
You can comment or delete the error line, or add the @ symbol in front of set_magic_quotes_runtime()
or configure;error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
PHPMailer and test file download: phpmailer.rar
http://www.bkjia.com/PHPjc/326254.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326254.htmlTechArticleAlthough php provides the mail() function, it is not easy to use, and PHPMailer is a good email sending tool , it is also very simple to use! Send emails using PHPMailer: Copy code...