Home php教程 php手册 PHPMailer发送邮件报错Msg:stream_socket_enable_crypto():

PHPMailer发送邮件报错Msg:stream_socket_enable_crypto():

May 25, 2016 pm 04:49 PM
phpmailer send email Report an error

今天在本机测试好的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 "邮件发送成功!";  
}
Copy after login

在使用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函数直接发送邮件哦.


文章网址:

随意转载^^但请附上教程地址。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Column count doesn't match value count at row 1 - How to solve MySQL error: column number does not match value Column count doesn't match value count at row 1 - How to solve MySQL error: column number does not match value Oct 05, 2023 am 11:40 AM

How to solve MySQL error: The number of columns does not match the value. Specific code examples are needed. When using the MySQL database for data operations, sometimes you will encounter the error message: "Columncountdoesn'tmatchvaluecountatrow1", which means that the number of columns does not match the number of values. match. This error usually occurs when inserting data and the number of columns specified is inconsistent with the number of values ​​inserted. This article describes specific workarounds and provides code examples. examine

Incorrect table definition; there can be only one auto column and it must be defined as a key - How to solve MySQL error: Incorrect table definition; there can be only one auto column and it must be defined as a key Incorrect table definition; there can be only one auto column and it must be defined as a key - How to solve MySQL error: Incorrect table definition; there can be only one auto column and it must be defined as a key Oct 05, 2023 am 11:05 AM

How to solve MySQL error: Wrong table definition; there can only be one automatic column and it must be defined as a key. Specific code examples are required. In recent years, MySQL database has become more and more widely used, but during use, we often encounter Various error reports. Among them, a common error is "wrong table definition; there can only be one automatic column and it must be defined as a key". This error usually occurs when we create a table, which may be a headache for beginners. This article will give you a detailed analysis of the reasons for this error and provide specific

mysql error 10060 mysql error 10060 Sep 12, 2023 am 11:00 AM

The solutions to mysql error 10060 include checking whether the MySQL server is running normally, checking the network connection, checking the firewall settings, checking the MySQL server configuration, checking the MySQL user permissions, checking the network configuration, checking the maximum number of connections limit of the MySQL server, and using the IP address instead of the host. Name and restart the MySQL server, etc. Detailed introduction: 1. Check whether the MySQL server is running normally. First, make sure the MySQL server is running and listening to the correct port, etc.

Cause analysis: HTTP request error 504 gateway timeout Cause analysis: HTTP request error 504 gateway timeout Feb 19, 2024 pm 05:12 PM

Brief introduction to the reason for the http request error: 504GatewayTimeout: During network communication, the client interacts with the server by sending HTTP requests. However, sometimes we may encounter some error messages during the process of sending the request. One of them is the 504GatewayTimeout error. This article will explore the causes and solutions to this error. What is the 504GatewayTimeout error? GatewayTimeo

Solution: Socket Error when handling HTTP requests Solution: Socket Error when handling HTTP requests Feb 25, 2024 pm 09:24 PM

http request error: Solution to SocketError When making network requests, we often encounter various errors. One of the common problems is SocketError. This error is thrown when our application cannot establish a connection with the server. In this article, we will discuss some common causes and solutions of SocketError. First, we need to understand what Socket is. Socket is a communication protocol that allows applications to

Step-by-step guide to quickly solve pyqt5 installation errors Step-by-step guide to quickly solve pyqt5 installation errors Jan 19, 2024 am 09:32 AM

If you are learning Python and want to develop GUI applications, PyQt5 is a very good choice. It is a bound version of the PyQt library under Python, which makes it very convenient to call and develop the Qt graphics library. However, sometimes you may encounter some problems when installing PyQt5. This guide will provide you with some steps to quickly solve installation error problems, and also attach specific code examples. Make sure the Python version is correct PyQt5 is a Python-based library, so first

Unknown column 'column_name' in 'where clause' - How to solve MySQL error: unknown column in where clause Unknown column 'column_name' in 'where clause' - How to solve MySQL error: unknown column in where clause Oct 05, 2023 am 11:15 AM

Unknowncolumn'column_name'in'whereclause'-How to solve MySQL error: unknown column in where clause, specific code example is needed MySQL is a widely used relational database management system, which supports the use of Structured Query Language (SQL) Storage, management and retrieval of data. However, when using MySQL to query, sometimes we will encounter errors. One of the common errors is: Unkno

Unknown database 'database_name' - How to solve MySQL error: unknown database name Unknown database 'database_name' - How to solve MySQL error: unknown database name Oct 05, 2023 am 09:45 AM

Unknown database 'database_name' - How to solve MySQL error: Unknown database name, specific code examples are needed When using MySQL, sometimes you will encounter the error message: Unknown database 'database_name'. This error message indicates that MySQL cannot find the database you specified. This may be because the database does not exist or you do not have permission to access the database. Below we'll explore some possible causes and provide specific code examples to resolve the issue. data

See all articles