简体   繁体   English

[SMTP:无法连接套接字:fsockopen():无法连接至ssl://smtp.gmail.com:465(未知错误)(代码:-1,响应:)]

[英][SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )]

I have been troubleshooting this issue for the last two months and have gotten no results on how to fix this. 在过去的两个月中,我一直在对该问题进行故障排除,但在解决此问题方面没有任何结果。 I am using PHP 5.6.3 with PEAR 1.10.1, the emailing pages in question worked fine with our 3-party emailing software on our local server only designed to use port 25 for SMTP. 我使用的是PHP 5.6.3和PEAR 1.10.1,有问题的电子邮件页面与本地服务器上的仅用于端口25的SMTP的3方电子邮件软件配合良好。 Now the PHP pages do reference an XML template that contains all the host, password, and username information. 现在,PHP页面确实引用了包含所有主机,密码和用户名信息的XML模板。 I want to switch to using google email servers with SSL. 我想切换为使用带有SSL的Google电子邮件服务器。 I implemented the changes provided by my email administrator and change the MX records accordingly. 我实施了电子邮件管理员提供的更改,并相应地更改了MX记录。 It was functioning properly for two weeks. 它正常运行了两个星期。 After that I was getting the following error 之后,我得到以下错误

"Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )]" . “无法连接到ssl://smtp.gmail.com:465 [SMTP:无法连接套接字:fsockopen():无法连接到ssl://smtp.gmail.com:465(未知错误)(代码: -1,响应:)]“

I have changed the code several times, I removed the ssl://, I have changed the protocol type to TLS with the port number 587, etc. Nothing was working! 我已经多次更改了代码,删除了ssl://,将协议类型更改为TLS,端口号为587,等等。什么都没用! I reached out to the contractor to construct a simple hard-coded page that just said hello world using the gmail server configuration. 我与承包商联系,以使用gmail服务器配置来构建一个简单的硬编码页面,该页面刚刚说出了问候世界。 He refused and made myself make a simple php page, mind you I had zero background in PHP programming until now, so on a side note entirely happy that this was thrown my way, but regardless I did complete the task. 他拒绝了,让我自己制作了一个简单的php页面,请记住,到目前为止,我在PHP编程方面的背景还为零。因此,顺便说一句,很高兴这被我抛弃了,但是无论我是否完成了任务。 I have a page that sends a simple message, using the smtp server with the account desired using the PHPMailer library. 我有一个页面,它使用smtp服务器以及使用PHPMailer库所需的帐户来发送一条简单的消息。 (See the code below) (请参见下面的代码)

 <?php  


require_once 'C:\Webpage\PHPMailer-5.2-stable/PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug   = 4; // 2 to enable SMTP debug information


$mail->Host = 'smtp.gmail.com';
$mail->Username = 'username@gmail.com';
$mail->Password = 'XXXXXXXXXXXXXXXXXXX';
$mail->SMTPSecure ='ssl';
$mail->Port = 465;

/*$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        //'allow_self_signed' => true
    )
);*/

$mail->From = 'XXXXt@abc.com';
$mail->FromName = 'Example';
$mail->addReplyTo('testing@abc.com','Example');
$mail->AddAddress('user1@xyz.com', 'John Doe');


$mail->Subject = 'Hello World';
$mail->Body ='A test email!';
$mail->AltBody = 'A test email!';



 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }
        ?>

Now I know this is not using PEAR, but from this I found out some interesting information that I think is related. 现在,我知道这并没有使用PEAR,但是从中我发现了一些我认为相关的有趣信息。 The code only works if the line with 该代码仅在以下行有效

 $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            //'allow_self_signed' => true
        )
);

is not commented out it works, but when it is commented out, I receive an error regarding this. 被注释掉是行不通的,但是注释掉后,我会收到关于此的错误消息。

Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [C:\Webpage\PHPMailer-5.2-stable\class.smtp.php line 299]

So I googled this error and was lead to the php.ini file to change the openssl.cafile and the openssl.capath values. 所以我用谷歌搜索了这个错误,导致php.ini文件更改了openssl.cafile和openssl.capath值。 I entered in the download CA certificates and entered the correct pathway for the values, but still it is not working. 我输入了下载的CA证书,并为这些值输入了正确的路径,但是仍然无法正常工作。 Am I placing these in the wrong area? 我会将它们放在错误的区域吗? Or is there an easier way to fix this issue using the PEAR library? 还是有使用PEAR库解决此问题的简便方法? Please any help on this subject will be appreciated!:) 请对此主题的任何帮助将不胜感激!:)

UPDATE(02/20/2018): 更新(02/20/2018):

I have downloaded the bundle and set the pathway to it's correct location, curl.cainfo ="C:\\OpenSSL-Win64\\bin\\PEM\\cacert.pem" , openssl.cafile="C:\\OpenSSL-Win64\\bin\\PEM\\cacert.pem" . 我已经下载了捆绑软件,并将路径设置为正确的位置, curl.cainfo ="C:\\OpenSSL-Win64\\bin\\PEM\\cacert.pem"openssl.cafile="C:\\OpenSSL-Win64\\bin\\PEM\\cacert.pem" I still am getting the error I ran the following check of the ssl locations to see if it was using the php.ini file and got the following. 我仍然遇到错误,我对ssl位置进行了以下检查,以查看它是否使用了php.ini文件并得到了以下内容。

    <?php
 error_reporting(E_ALL);

print "\nIf you've got this far without errors then problem is with your SSL config\n";
 $calocns=openssl_get_cert_locations();
 if (count($calocns)) {
     print "Check you've got your cacerts deployed in one of the following locations\n";
     foreach ($calocns as $k=>$v) print "$k = $v\n";
 } else {
     print "You've not configured your openssl installation on this host\n";
 }
$calocns=openssl_get_cert_locations();
//var_dump(openssl_get_cert_locations());


?>

Result: 结果:

    If you've got this far without errors then problem is with your SSL config Check you've got your cacerts deployed in one of the following locations default_cert_file = f:\repo\winlibs_openssl_vc11_x86/cert.pem default_cert_file_env = SSL_CERT_FILE 
    default_cert_dir = f:\repo\winlibs_openssl_vc11_x86/certs 
    default_cert_dir_env = SSL_CERT_DIR 
    default_private_dir = f:\repo\winlibs_openssl_vc11_x86/private
 default_default_cert_area = f:\repo\winlibs_openssl_vc11_x86 
    ini_cafile = 
    ini_capath = 

I seem to be doing this wrong or need to know how to change the locations because those locations are not existent on my computer and I don't understand how it goes to those by default when I changed the pathway in the configuration file itself. 我似乎做错了此事,或者需要知道如何更改位置,因为这些位置在我的计算机上不存在,并且当我在配置文件本身中更改路径时,默认情况下我不知道该如何处理这些位置。 Any thoughts? 有什么想法吗?

Obviously it's still the certificate issue. 显然,这仍然是证书问题。 Try using the latest CA certificates extracted from Mozilla . 尝试使用从Mozilla提取最新CA证书 Simply download it, place it somewhere or replace your current cacert.perm , add the path to your certificate to openssl.cafile and curl.cainfo in your php.ini , and then try again. 只需下载它,将其放置在某个地方或替换当前的cacert.perm ,将证书的路径添加到php.ini openssl.cafilecurl.cainfo ,然后重试。 You might want to comment openssl.capath for now. 您可能现在要评论openssl.capath

You can read more about issues related to CA certificate in PHPMailer Troubleshooting Wiki . 您可以在PHPMailer故障排除Wiki中阅读有关与CA证书有关的问题的更多信息


Update for 02/20/2018: 2018年2月20日更新:

The curl.cainfo and openssl.cafile paths looks fine, assuming that is the correct path to the cacert.pem you downloaded. curl.cainfoopenssl.cafile路径看起来不错,假设这是您下载的cacert.pem的正确路径。 However your ini_cafile is empty when you run openssl_get_cert_locations() . 但是,当您运行openssl_get_cert_locations()时,您的ini_cafile为空。 It should reflect whatever you set in your openssl.cafile . 它应该反映您在openssl.cafile设置的任何内容。 You will need to restart your web server (Apache/nginx) after making changes to your php.ini to take effect. php.ini进行更改后,您将需要重新启动Web服务器(Apache / nginx)。 After restarting check the openssl.cafile value by running phpinfo() , and make sure it is correct. 重新启动后,通过运行phpinfo()检查openssl.cafile值,并确保它是正确的。

I'm not sure why the default cert directory is like that. 我不确定为什么默认的证书目录是这样的。 Maybe a previous installation of Open SSL? 也许是以前安装的Open SSL? Either way, it's an non-existent default path for me as well but it doesn't matter since my ini_cafile shows the same value I defined in openssl.cafile . 无论哪种方式,这对我来说都不是默认路径,但这并不重要,因为我的ini_cafile显示的是我在openssl.cafile定义的相同值。 openssl_get_cert_locations() shows the list of places it will be looking for the certificates, so if the correct one is among the them, I think it should be fine. openssl_get_cert_locations()显示了它将在其中查找证书的位置的列表,因此,如果其中包含正确的证书,我认为应该没问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决错误:消息:fsockopen():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝) - How to resolve the error: Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) 在Codeigniter中无法发送电子邮件-fsockopen():无法连接到ssl://smtp.gmail.com:465(连接被拒绝) - in Codeigniter Unable to send email - fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) 消息:fsockopen():无法连接到ssl://smtp.gmail.com:465(连接超时) - Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) 连接失败。 错误 #2:stream_socket_client():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝) - Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) Connection could not be established with host smtp.gmail.com:stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 - Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 CodeIgniter电子邮件:fsockopen():无法连接到ssl://smtp.gmail.com托管中 - CodeIgniter email: fsockopen(): Unable to connect to ssl: //smtp.gmail.com in hosting 讯息:fsockopen():无法连接至ssl://smtp.googlemail.com:465(权限被拒绝) - Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Permission denied) Codeigniter电子邮件无法在服务器fsockopen()中工作:无法连接至ssl://smtp.googlemail.com:465(连接被拒绝) - Codeigniter Email did not Working in Server fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection refused) 我的网站在本地发送邮件,gmail,但不在服务器上发送。 无法连接到ssl://smtp.gmail.com - My website sends mail ,gmail, locally but not on server. Unable to connect to ssl://smtp.gmail.com Laravel 3-错误:与smtp.gmail.com的连接:465超时 - Laravel 3 - error: Connection to smtp.gmail.com:465 Timed Out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM