今天在本机测试好的phpmailer邮箱发送功能没有问题,本地是windows apache php环境但在了linux中发送邮件就出现了Msg:stream_socket_enable_crypto(): this stream does not support SSL/crypto错误了,后来我分析了N久得出一办法,下面分享给各位朋友。
我的PHPMailer发送邮件代码
- header("Content-type:text/html;charset=utf-8");
- include('phpmailer/class.phpmailer.php');
- include('phpmailer/class.smtp.php');
-
- $mail = new PHPMailer();
-
- $mail->IsSMTP();
- $mail->Host = "smtp.sohu.com";
- $mail->Port = 25;
- $mail->SMTPAuth = true;
- $mail->Username = "yourmail@sohu.com";
- $mail->Password = "yourmail168";
- $mail->From = "spr_zsql@163.com";
- $mail->FromName = "test";
- $mail->AddAddress("yourmail@qq.com", "test");
-
- $mail->WordWrap = 50;
-
-
- $mail->IsHTML(true);
-
- $mail->Subject = "测试";
- $mail->Body = "测试";
-
- if(!$mail->Send())
- {
- echo "Mailer Error: " . $mail->ErrorInfo;
- echo "发送邮件错误!";
- }else{
- echo "邮件发送成功!";
- }
在使用PHPMailer发送邮件报错Msg:stream_socket_enable_crypto(): this stream does not support SSL/crypto,出现这种情况请输出phpinfo()看下openssl这个扩展没有安装,查找php安装时源码包的位置以/usr/local/src/php/php-5.3为例子,代码如下:
cd /usr/local/src/php/php-5.3/ext/openssl
/usr/local/php/bin/phpize
可能会出现下面的错误,代码如下:
Cannot find config.m4.
Make sure that you run ‘/usr/local/php/bin/phpize’ in the top level source directory of the module
解决办法,代码如下:
mv config0.m4 config.m4
/usr/local/php/bin/phpize
./configure --with-openssl --with-php-config=/usr/local/php/bin/php-config
make && make install安装成功后会有以下提示
Build complete.
Don’t forget to run ‘make test’.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ 改目录下回生成一个openssl.so文件,找到php的配置文件,在扩展区域添加如下代码:
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/openssl.so
ps -ef | grep php-fpm | grep -v grep | awk '{print $2}'|xargs kill -9
/usr/local/php/sbin/php-fpm
如果你配置了还不能发送邮箱我们可以尝试在linux中直接使用mail函数直接发送邮件哦. |