【问题标题】:Problem with using PHPMailer for SMTP将 PHPMailer 用于 SMTP 的问题
【发布时间】:2011-09-23 07:51:22
【问题描述】:

我已将 PHPMailer 用于 SMTP,但在发送邮件时出现错误“Mailer Error: The following From address failed: no-reply@mydomain.org.uk”

我的代码如下:

        $mail = new PHPMailer();

        $mail->IsSMTP();                                   // send via SMTP

        $mail->Host = "localhost;"; // SMTP servers

        $mail->SMTPAuth = true;     // turn on SMTP authentication

        $mail->Username = "";  // SMTP username

        $mail->Password = ""; // SMTP password



        $mail->From = $email_address;

        $mail->FromName = $email_address;

        $mail->AddAddress($arrStudent[0]["email"]);

        $mail->WordWrap = 50;                              // set word wrap

        $mail->IsHTML(true);                               // send as HTML



        $mail->Subject = "Subject";

        $theData = str_replace("\n", "<BR>", $stuff);

        $mail->Body = $theData; // "This is the <b>HTML body</b>";

        $mail->AltBody = $stuff;




        if (!$mail->Send()) {

            $sent = 0;

            echo "Mailer Error: " . $mail->ErrorInfo;

            exit;

        }

我研究了所有内容,当我在 class.smtp.php 中调试时发现错误,函数“get_lines()”返回错误值“550 Authentication failed”

代码之前运行良好,我想知道这个问题是怎么突然出现的。 迫切需要一些帮助。

谢谢, 双实验室

【问题讨论】:

  • 550 Authentication failed 看起来很清晰。也许您用于此的 SMTP 帐户毕竟有用户名和密码
  • @Pekka:等等,你是说错误消息实际上意味着什么?我很震惊,震惊! ;)
  • 我也这么认为....但之前使用相同的代码运行良好,并且空间提供者由于他们的问题而没有提供此信息。
  • @Frozenfire 如前所述 - `也许你用于此的 SMTP 帐户毕竟有用户名和密码`
  • 嗯...也许...所以我应该咨询空间提供商或其他人?

标签: php smtp phpmailer


【解决方案1】:
public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
    require_once('mailer.class.php');
    $mailer = new PHPMailer();
    //do we use SMTP?
    if ( USE_SMTP ) {
        $mailer->IsSMTP();
        $mailer->SMTPAuth = true;
        $mailer->Host = SMTP_HOST;
        $mailer->Port = SMTP_PORT;
        $mailer->Password = '';
        $mailer->Username = '';
        if(USE_SSL)
            $mailer->SMTPSecure = "ssl";
    }

    $mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
    $mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );

    $mailer->AddAddress($to);
    $mailer->Subject = $subject;
    //$mailer->WordWrap = 100;
    $mailer->IsHTML ( TRUE );
    $mailer->MsgHTML($body);

    require_once('util.class.php');
    $mailer->AltBody  =  Util::html2text ( $body );

    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if ( ! $mailer->Send() ) {
        return FALSE;
    }
    else {
        $mailer->ClearAllRecipients ();
        $mailer->ClearReplyTos ();
        return TRUE;
    }
}

我曾经这样使用过... SetFrom 应该用来代替 From... 那是您的错误伙伴... :))

【讨论】:

  • no dude....我的 PHPMailer 类中没有任何 SetFrom 函数...那里显然有 $From 变量..
【解决方案2】:

尝试将下面的行添加到 php.ini

extension=php_openssl.dll

重启再试

【讨论】:

    【解决方案3】:

    我正在使用 YII 的 Mailer 和 PHPMailer,这对我有用:

    $mail = Yii::createComponent('application.extensions.mailer.EMailer');
    $mail->Username           = $this->SMTP_USERNAME;  // SMTP username
    $mail->Password           = $this->SMTP_PASSWORD; // SMTP password
    $mail->SMTPAuth           = true;
    $mail->From               = $this->fromAddress;
    $mail->Host               = $this->SMTP_SERVER_ADDRESS;
    $mail->FromName           = $this->fromName;
    $mail->CharSet            = 'UTF-8';
    $mail->Subject            = Yii::t('mailer', $this->subject);
    $mail->Body               = $this->message;
    $mail->AddReplyTo($this->toAddress);
    $mail->AddAddress($this->toAddress);
    $mail->IsSMTP(true);
    $mail->IsHTML(true);
    $mail->Send();
    

    希望有帮助吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2017-03-11
      • 1970-01-01
      • 2019-09-18
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多