Phpmailer“消息已成功发送”但未发送邮件?

时间:2015-12-03 14:35:10

标签: php phpmailer

当我尝试使用此代码发送电子邮件时,我明白了 “消息已成功发送”但当我检查我的雅虎收件箱和垃圾邮件文件夹时,我发现邮件未送达。     

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)

1 个答案:

答案 0 :(得分:-1)

您需要将SMTP设置为SMTP服务器。您需要做的就是:设置$mail -> host = smtp.mail.yahoo.com。除此之外,您需要将端口设置为587.请查看Google以了解如何将yahoo设置为smtp服务器以及如何对自己进行身份验证。