【问题标题】:Mail delivered failed using PHPMailer in PHP在 PHP 中使用 PHPMailer 发送邮件失败
【发布时间】:2017-05-19 22:33:21
【问题描述】:

如果我在 HTML 邮件中添加锚标记然后邮件传递显示失败,则一切正常。

include("mail/class.phpmailer.php");
include("mail/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'user@gmail.com';
$mail->Password = 'password';
$mail->SMTPAuth = true;
$mail->From = 'user@gmail.com';
$mail->FromName = 'Naren';
$mail->AddAddress('xyz@gmail.com');
//$mail->AddReplyTo('xyz@gmail.com', 'Information');
$mail->IsHTML(true);
$mail->Subject    = "code";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
$mail->Body    = "<!DOCTYPE HTML><html>
<head>
<title>HTML email</title>
</head>
<body>
<p>Hello, This is test mail</p>
<a href='http://www.domain.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
</body>
</html>";

if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

如果我从正文中删除锚标记,那么工作正常,但如果我添加锚标记,那么我会收到一封邮件发送失败的电子邮件。你会在这方面帮助我吗?

【问题讨论】:

  • 您在 error.log 上是否有任何错误?试着打开日志看看有没有错误
  • 感谢 Rafael 先生的回复,我没有收到任何错误消息。
  • 你有没有在你的身体上方添加这个? $mail->isHTML(true);
  • 是的,如果您需要我的完整代码,我补充说。我会更新它
  • 如果您收到一封电子邮件说发送失败,那么您发送成功,并且您的邮件可能被垃圾邮件过滤器退回。除此之外,您还没有真正包含足够的信息来继续。阅读 PHPMailer 故障排除指南。

标签: php html email smtp phpmailer


【解决方案1】:

你应该正确关闭“a href”,你忘了'(单引号)

代替:

<a href='http://www.domain.com/changepassword.php?user_id=" .$User_id1."'>

你应该使用:

<a href='http://www.domain.com/changepassword.php?user_id='" .$User_id1."'>

【讨论】:

  • 从什么时候开始有关系?我更喜欢我的 id 没有引号。
  • Sylwester 先生,我现在收到垃圾邮件了
  • Xorifelse 先生,您能帮我解决这个问题吗?
【解决方案2】:

最后,我找到了答案。我尝试了下面的代码,它对我来说非常有效。

<a href='http://www.domain.com/changepassword.php?user_id=$User_id1'>Create your password here</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多