0

我被要求使用外部 SMTP 服务器,说明如下:

“我们希望您以明文形式连接到端口 25,然后发出 STARTTLS 以开始 TLS/SSL。然后登录”

这可能吗?如果可以,我应该怎么做?据我了解,这与在 smtp 连接数组中将 TLS 设置为 true 不同,对吗?

更新在这里走向胜利。查看 SmtpTransport.php 中的代码,我可以看到它与注释中链接的规范相匹配(显然),但块 102-107 似乎将主机设置为客户端或本地主机 - 我在主机配置。我做错了吗?

蛋糕代码:

protected function _connect() {
    $this->_generateSocket();
    if (!$this->_socket->connect()) {
        throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.'));
    }
    $this->_smtpSend(null, '220');

    if (isset($this->_config['client'])) {
        $host = $this->_config['client'];
    } elseif ($httpHost = env('HTTP_HOST')) {
        list($host) = explode(':', $httpHost);
    } else {
        $host = 'localhost';
    }

    try {
        $this->_smtpSend("EHLO {$host}", '250');
        if ($this->_config['tls']) {
            $this->_smtpSend("STARTTLS", '220');
            $this->_socket->enableCrypto('tls');
            $this->_smtpSend("EHLO {$host}", '250');
        }
    } catch (SocketException $e) {
        if ($this->_config['tls']) {
            throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'));
        }
        try {
            $this->_smtpSend("HELO {$host}", '250');
        } catch (SocketException $e2) {
            throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection.'));
        }
    }
}

我的电子邮件配置:

    public $smtp = array(
    'transport' => 'Smtp',
    'from' => array('me@example.com' => 'my name'),
    'host' => 'secretipaddress',
    'port' => 25,
    'timeout' => 30,
    'username' => 'me@example.com',
    'password' => 'secretpassword',
    'client' => null,
    'log' => true,
    'tls' => true
);
4

1 回答 1

0

在您的配置文件 app.php 中启用“tls”为真。它适用于我和 cakephp 3.1 与 gmail smtp

于 2017-03-04T10:32:31.907 回答