stream_socket_enable_crypto(): this stream does not

今天在Yii框架中调用PHPMailer发送邮件的时候(使用SMTP的TLS加密认证方式)出现错误,在网上Google了下,找到一篇文章解决了问题(stackoverflow上也有相关问题及解答,点这里查看)。原文内容如下:

“Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto” is a message you will often come across when doing mail send work in PHP, particularly when your SMTP settings require you to connect using either a SSL or TLS mode.

The reason for the PHP warning message is actually not insidious at all – 99% of the time it refers to the fact that the OpenSSL extension hasn’t been enabled in your PHP configuration file – and under XAMPP this is almost always the case.

So a simple fix is to navigate to your php.ini file (for XAMPP it usually sits under xamppapacheinphp.ini), open it up and run a search for “extension=php_openssl.dll”.

Uncomment this line by removing the semi-colon at the front of it, save the file and then restart Apache via the Services panel.

以上英文的概要意思是:我们经常在使用PHP处理邮件发送的时候遇到这个问题,而且出现这个问题99%的原因是没有安装或启用PHP扩展openssl,安装openssl后,在php.ini文件去去掉extension=php_openssl.dll前的注释,然后重启apache即可解决这个问题。

在Linux下,如果是编译安装的PHP,可以通过在命令行输入php -m,也可以通过在浏览器查看phpinfo来检查是否安装了openssl扩展,如果没有,可以通过如下方式快速安装:

sudo apt-get install openssl libcurl3-openssl-dev #需要先安装openssl
#进入php源码解压目录
cd /path/to/php/ext/openssl
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-openssl
make
sudo make install

安装成功后在php.ini中加上

extension=openssl.so

然后重启apache即可,看到phpinfo打印如下信息,则代表安装成功:

openssl

这样再使用PHPMailer以SMTP加密方式发送邮件就不会报错了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值