今天在本机测试好的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(); // set mailer to use SMTP $mail->Host = "smtp.sohu.com"; // SMTP服务器 $mail->Port = 25; $mail->SMTPAuth = true; // SMTP认证? $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->AddAttachment("/var/tmp/file.tar.gz"); // 附件 //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // 附件,新文件名 $mail->IsHTML(true); // HTML格式 $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函数直接发送邮件哦.
文章网址:
随意转载^^但请附上教程地址。