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打印如下信息,则代表安装成功:

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

你可能感兴趣的:(后台开发)