我知道这个问题已经被问过,但没有答案可以帮助我。
这是我的代码,希望您能找到错误。
<?php
require("phpMailer/class.phpmailer.php");
require("phpMailer/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$mail->Username = "mailer@example.com"; // SMTP username
$mail->Password = "validpassword"; // SMTP password
$mail->From = "mailer@example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("my.email@gmail.com");
$mail->AddReplyTo("mailer@example.com", "Mailer");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
PS:有趣的事实是我的邮件不会通过mailer()进入垃圾邮件......但我必须使用Phpmailer。