【问题标题】:php 5.6 mail and SSLphp 5.6 邮件和 SSL
【发布时间】:2016-10-05 11:16:10
【问题描述】:

我发现自己升级到php5.6后无法发送邮件了。

$to = "Test1 <*******@gmail.com>";
$body = "Hi,\n\n this is just test email";

$headers = array(
    'From' => '*******@gmail.com',
    'To' => $to,
    'Subject' => 'test email'
);

$smtp = Mail::factory('smtp', array(
    'host' => 'smtp.sendgrid.com',
    'port' => '587',
    'auth' => 'login',
    'username' => '*****',
    'password' => '*****',
));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo $mail->getMessage();
} else {
    echo "<p> Message successfully sent!</p>";
}

登录验证失败[SMTP:STARTTLS 失败(代码:220,响应:立即开始 TLS 协商)]

如果我通过此代码使用我的 Gmail 帐户,我也会收到错误

$smtp = Mail::factory('smtp',array (
    'host' => 'ssl://smtp.googlemail.com',
    'port' => '465',
    'auth' => 'login',
    'username' => '******@gmail.com',
    'password' => '*******'
));

身份验证失败 [SMTP:从服务器收到的响应代码无效(代码:534,响应:5.7.14 请通过 Web 浏览器登录,然后 5.7.14 再试一次。5.7.14 了解更多信息,请访问 5.7.14 @987654321 @jz4sm22875767wjb.16-gsmtp)]

我有一个用 ZF1 运行的 oid 应用程序,我发现这个调用 Zend_Mail_Protocol_Smtp 有问题:

stream_socket_enable_crypto($this-&gt;_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)

我读到 php 5.6 对 OpenSSL 进行了一些更改,但我不知道我需要做哪些更改。

【问题讨论】:

  • 您找到解决此问题的方法了吗?我正在经历同样的问题..谢谢

标签: email openssl pear


【解决方案1】:

我遇到了同样的问题并偶然发现了解决方案,而这些显然与 PHP 5.6 中的更改有关(我对此并不满意)。

  1. verify_peer 和 verify_peer_name 现在默认设置为 true - 需要在流式端口中涉及的两台机器之间提供额外的安全级别。当我处理 SMTP 时,我不想要这个,STARTTLS 加密对我来说就足够了。所以关闭这些我在 Net/SMTP.php 文件中添加了一些代码

    $options = array('ssl' => array('verify_peer_name' => false, 'verify_peer' => false));

    $result = $this->_socket->connect($this->host, $this->port, $persistent, $timeout, $options);

  2. 此函数未使用 php.ini 中指定的套接字超时默认值。所以我将'smtp.php'中的默认值更改为:

    $超时 = 60; // 以前为空;

希望对其他人有所帮助。干杯穆雷

【讨论】:

    【解决方案2】:

    我知道这个问题有点老了,但我会在这里留下答案,也许其他人会觉得它有用:https://stackoverflow.com/a/34090707/5639805

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多