【问题标题】:Failed to connect to smtp.gmail.com:587无法连接到 smtp.gmail.com:587
【发布时间】:2018-08-22 06:12:09
【问题描述】:

我在 Yii 框架中使用 pear 邮件库时使用了这个错误

无法连接到 smtp.gmail.com:587 [SMTP:HELO 未被接受(代码:-1,响应:)] 错误代码:10001

包含的配置文件

'zebrostMailer' => array(
            'class' => 'application.extensions.zebrostMailer.CZebrostMailer',
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'helo' => '',
            'auth' => true,
            'username' => 'user@gmail.com',
            'password' => '*******',
            'from' => 'TestUser',
            'timeout' => '5',
            'SMTPAuth' => true,
            'SMTPSecure' => 'tls',

        ),

phpmailer.php

<?php

include('Mail.php'); 包括('Mail/mime.php');

类 CZebrostMailer 扩展 CApplicationComponent {

public $host;
public $port;
public $helo;
public $auth;
public $username;
public $password;
public $from;
public $timeout;
public $SMTPAuth;
public $SMTPSecure;
public $Mailer;

public function SendEmail($to, $subject, $body, $htmlImages = null) {
    $mime = new Mail_mime();
    $headers = array(
        'From' => $this->from,
        'To' => $to,
        'Subject' => $subject
    );
    @$mime->setHTMLBody($body);
    if ($htmlImages) {
        foreach ($htmlImages as $htmlImage) {
            $mime->addHTMLImage(
                    $htmlImage, Yii::app()->zebrostGenFuncs->getMimeType($htmlImage)
            );
        }
    }
    $body = @$mime->get();
    $headers = @$mime->headers($headers);
    $smtp = @Mail::factory('smtp', array(
                'host' => $this->host,
                'port' => $this->port,
                'localhost' => $this->helo,
                'auth' => $this->auth,
                'username' => $this->username,
                'password' => $this->password,
                'timeout' => $this->timeout,
                'SMTPSecure' => $this->SMTPSecure,
                'SMTPAuth' => $this->SMTPAuth,

    ));
    if (@PEAR::isError($smtp)) {
        throw new CException(@$smtp->getMessage() . ' Error code:' . @$smtp->getCode());
    }
    $mail = @$smtp->send($to, $headers, $body);
    if (@PEAR::isError($mail)) {
        throw new CException(@$mail->getMessage() . ' Error code:' . @$mail->getCode());
    }
}

}

我被卡住了,请帮帮我

【问题讨论】:

    标签: email smtp yii2-advanced-app


    【解决方案1】:

    我在发布问题的同一天得到了问题的解决方案。 唯一的问题是我向 smtp.gmail.com 发送空白的“helo” 这就是未建立连接的原因。

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 1970-01-01
      • 2013-08-21
      • 2019-09-20
      • 1970-01-01
      • 2019-09-08
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多