【问题标题】:Phpmailer "Message has been sent successfully" but not delivered mail?Phpmailer“消息已发送成功”但未发送邮件?
【发布时间】:2015-12-03 14:35:09
【问题描述】:

当我尝试使用此代码发送电子邮件时,我得到 “邮件已成功发送”但是当我检查我的雅虎收件箱和垃圾邮件文件夹时,我发现邮件没有送达。

function sendmail(){
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->IsMail();
$mail->From = "my.mail@yahoo.com";
$mail->FromName = "Name";

//To address and name
$mail->addAddress("my.mail@yahoo.com", "Recepient Name");

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

var_dump($mail);

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

当我 var_dump($mail) 查看设置了哪些参数时,我得到了这个:

object(PHPMailer)[1]
  public 'Version' => string '5.2.14' (length=6)
  public 'Priority' => null
  public 'CharSet' => string 'iso-8859-1' (length=10)
  public 'ContentType' => string 'text/html' (length=9)
  public 'Encoding' => string '8bit' (length=4)
  public 'ErrorInfo' => string '' (length=0)
  public 'From' => string 'my.mail@yahoo.com' (length=22)
  public 'FromName' => string 'Name' (length=6)
  public 'Sender' => string '' (length=0)
  public 'ReturnPath' => string '' (length=0)
  public 'Subject' => string 'Subject Text' (length=12)
  public 'Body' => string '<i>Mail body in HTML</i>' (length=24)
  public 'AltBody' => string 'This is the plain text version of the email content' (length=51)
  public 'Ical' => string '' (length=0)
  protected 'MIMEBody' => string '' (length=0)
  protected 'MIMEHeader' => string '' (length=0)
  protected 'mailHeader' => string '' (length=0)
  public 'WordWrap' => int 0
  public 'Mailer' => string 'mail' (length=4)
  public 'Sendmail' => string '/usr/sbin/sendmail' (length=18)
  public 'UseSendmailOptions' => boolean true
  public 'PluginDir' => string '' (length=0)
  public 'ConfirmReadingTo' => string '' (length=0)
  public 'Hostname' => string '' (length=0)
  public 'MessageID' => string '' (length=0)
  public 'MessageDate' => string '' (length=0)
  public 'Host' => string 'localhost' (length=9)
  public 'Port' => int 25
  public 'Helo' => string '' (length=0)
  public 'SMTPSecure' => string '' (length=0)
  public 'SMTPAutoTLS' => boolean true
  public 'SMTPAuth' => boolean false
  public 'SMTPOptions' => 
    array (size=0)
      empty
  public 'Username' => string '' (length=0)
  public 'Password' => string '' (length=0)
  public 'AuthType' => string '' (length=0)
  public 'Realm' => string '' (length=0)
  public 'Workstation' => string '' (length=0)
  public 'Timeout' => int 300
  public 'SMTPDebug' => int 0
  public 'Debugoutput' => string 'echo' (length=4)
  public 'SMTPKeepAlive' => boolean false
  public 'SingleTo' => boolean false
  public 'SingleToArray' => 
    array (size=0)
      empty
  public 'do_verp' => boolean false
  public 'AllowEmpty' => boolean false
  public 'LE' => string '
' (length=1)
  public 'DKIM_selector' => string '' (length=0)
  public 'DKIM_identity' => string '' (length=0)
  public 'DKIM_passphrase' => string '' (length=0)
  public 'DKIM_domain' => string '' (length=0)
  public 'DKIM_private' => string '' (length=0)
  public 'action_function' => string '' (length=0)
  public 'XMailer' => string '' (length=0)
  protected 'smtp' => null
  protected 'to' => 
    array (size=1)
      0 => 
        array (size=2)
          0 => string 'my.mail@yahoo.com' (length=22)
          1 => string 'Recepient Name' (length=14)
  protected 'cc' => 
    array (size=0)
      empty
  protected 'bcc' => 
    array (size=0)
      empty
  protected 'ReplyTo' => 
    array (size=0)
      empty
  protected 'all_recipients' => 
    array (size=1)
      'my.mail@yahoo.com' => boolean true
  protected 'RecipientsQueue' => 
    array (size=0)
      empty
  protected 'ReplyToQueue' => 
    array (size=0)
      empty
  protected 'attachment' => 
    array (size=0)
      empty
  protected 'CustomHeader' => 
    array (size=0)
      empty
  protected 'lastMessageID' => string '' (length=0)
  protected 'message_type' => string '' (length=0)
  protected 'boundary' => 
    array (size=0)
      empty
  protected 'language' => 
    array (size=0)
      empty
  protected 'error_count' => int 0
  protected 'sign_cert_file' => string '' (length=0)
  protected 'sign_key_file' => string '' (length=0)
  protected 'sign_extracerts_file' => string '' (length=0)
  protected 'sign_key_pass' => string '' (length=0)
  protected 'exceptions' => boolean false
  protected 'uniqueid' => string '' (length=0)

【问题讨论】:

  • 您使用的是isMail()(无论如何都是默认设置),因此您的邮件将通过您的本地邮件服务器发送。当它报告成功时,这意味着它已成功地将其发送到您的本地邮件服务器,而不是进一步发送。要了解之后发生的情况,请查看您的邮件服务器日志文件,通常是/var/log/mail.log
  • 当我尝试通过 ssh 访问 /var/log/mail.log 时,我收到权限被拒绝消息...
  • 使用sudo?您在使用共享主机吗?
  • 我试过这个 tail -n 100 /var/log/mail.log。是的,cloudways 服务器。
  • 有趣的是wordpress newsletter 插件可以发送邮件,但是其他一些邮件插件以及wordpress mail() 和phpmailer 不能。

标签: php phpmailer


【解决方案1】:

您需要将 gmail 设置为 SMTP 服务器。为此,您必须做的事情包括:设置$mail -&gt; host = smtp.mail.yahoo.com。除此之外,您还需要将端口设置为 587。查看 google 以了解如何将 yahoo 设置为 smtp 服务器以及如何进行身份验证。

【讨论】:

  • 我可以不用认证就使用phpmailer吗?
  • 不,可能不是。至少我无法在未经身份验证的情况下发送带有 gmail 的电子邮件。它可能对雅虎也有效(但为了确保您需要,您可以尝试使用和不使用身份验证发送)。
  • 这不是真的。您不必使用 SMTP。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-25
  • 1970-01-01
  • 1970-01-01
  • 2016-03-16
  • 2018-07-09
  • 2016-02-18
  • 2017-09-29
相关资源
最近更新 更多