【问题标题】:sending mail through PHPMailer通过 PHPMailer 发送邮件
【发布时间】:2017-05-06 13:01:14
【问题描述】:

我正在尝试通过 PHP Mailer 发送邮件,但遇到了这样的错误

错误:

SMTP 错误:MAIL FROM 命令失败:530-5.5.1 需要身份验证。了解更多 at530 5.5.1 https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 - gsmtp 以下发件人地址失败:我的电子邮件地址@gmail.com:MAIL FROM 命令失败,需要身份验证。在https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 了解更多信息 - gsmtp,530,5.5.1SMTP 服务器错误:MAIL FROM 命令失败详细信息:需要身份验证。了解更多信息 无法发送消息

   <?php

require_once ('PHPMailer-master/class.pop3.php');
require_once ('PHPMailer-master/class.smtp.php');
require_once ("PHPMailer-master/class.phpmailer.php");
require_once ("PHPMailer-master/PHPMailerAutoload.php");
   $mail = new PHPMailer();
   $mail->isSMTP();
   $mail->Host = "smtp.gmail.com";
   $mail->SMTPAuth = false;
   $mail->SMTPDebug =1;
   $mail->Debugoutput = 'html';
   $mail->Port = 587;
   $mail->SMTPSecure = 'tls';
   $mail->Username = "my email address";
   $mail->Password = "email password";
   $mail->setFrom("email address","name");
   $mail->addAddress("my friend email address");
   $mail->Subject = 'First Mailer in Php';
   $mail->Body= 'this is first mail...sending through php code';
   if(!$mail->send()){
       echo "Message cannot be send"."<br/>";
       echo "MailerError".$mail->ErrorInfo;
       exit;
   }else{
       echo "<script>window.alert('Message has been sent');</script>";
   }

 ?>

谁能帮我弄清楚这里发生了什么。 ?谢谢

【问题讨论】:

    标签: php email error-handling phpmailer


    【解决方案1】:

    不要只是在你的代码中添加随机的东西,希望它会有所帮助!您唯一需要的就是自动装载机。将您的代码基于the gmail example provided with PHPMailer,或者至少是自述文件中提供的基本示例。

    从错误消息中您可以确切地看到问题所在 - 当您设置了 UsernamePassword 属性时,您已禁用身份验证。像这样启用它。

    $mail->SMTPAuth = true;
    

    您还使用旧版本的 PHPMailer,所以get the latest

    【讨论】:

    • 非常感谢...@Snchro...它的工作完美....感谢您的考虑.... :)
    【解决方案2】:

    你错过了这个变量:

    $mail->SMTPSecure = "tls";
    

     $mail->SMTPSecure = "ssl";
    

    试一试。

    【讨论】:

    • 我试过了,......但仍然有一个错误......无论如何感谢您的回答...... :) @prakashtank
    • 您检查过使用的 gmail 帐户设置吗? wpsitecare.com/gmail-smtp-settings请检查一次。
    • 我刚刚编辑了我的帖子..我有以下我上面提到的错误..帮助我纠正这些错误..谢谢..
    猜你喜欢
    • 1970-01-01
    • 2021-03-23
    • 2012-05-26
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2011-12-19
    • 2018-09-29
    • 1970-01-01
    相关资源
    最近更新 更多