PEAR 邮件无法连接到 Gmail SMTP,无法连接到套接字 [英] PEAR Mail unable to connect to Gmail SMTP, failed to connect to socket

查看:37
本文介绍了PEAR 邮件无法连接到 Gmail SMTP,无法连接到套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实

我正在使用 PEAR 邮件,我想使用 gmail SMTP 发送邮件.我有 Apache/2.4.27 (Win64) PHP/7.2.0beta3、PEAR 1.10.15、Mail 1.4.1、Net_SMTP 1.8.0、Net_Socket 1.2.2.

I am using PEAR Mail, I want to use gmail SMTP to send a mail. I have Apache/2.4.27 (Win64) PHP/7.2.0beta3, PEAR 1.10.15, Mail 1.4.1, Net_SMTP 1.8.0, Net_Socket 1.2.2.

我去php.ini 并添加了extension = php_openssl.dll.error.log 没有给出与 ssl 相关的错误.

I went to php.ini and added extension = php_openssl.dll. The error.log gives no ssl-related errors.

这是代码

require_once "Mail.php";

$from = '<slevin@gmail.com>';
$to = '<slevinkelevra@gmal.com>';
$subject = 'Hi!';
$body = "Hi,

How are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'slevinmail@gmail.com',
        'password' => 'mypassword'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

问题

我收到这个错误

无法连接到 ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: fsockopen(): 无法连接到 ssl://smtp.gmail.com:465 (Unknown错误)(代码:-1,响应:)]

我不知道该怎么做,我用谷歌搜索,但我更困惑了.

and I have no clue what to do, I Googled but I got more confused.

请就如何解决此问题提出建议.谢谢

Please advice on how to fix this. Thank you

更新

按照 symcbean 的说明,我得到了以下结果:

Following symcbean's instructions I got the following results :

bool(true) 

array(5) { 
[0]=> string(31) "alt3.gmail-smtp-in.l.google.com" 
[1]=> string(26) "gmail-smtp-in.l.google.com" 
[2]=> string(31) "alt4.gmail-smtp-in.l.google.com" 
[3]=> string(31) "alt1.gmail-smtp-in.l.google.com" 
[4]=> string(31) "alt2.gmail-smtp-in.l.google.com" } 
IPV4 address = 64.233.188.27

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 = C:Program FilesCommon FilesSSL/cert.pem
default_cert_file_env = SSL_CERT_FILE
default_cert_dir = C:Program FilesCommon FilesSSL/certs
default_cert_dir_env = SSL_CERT_DIR
default_private_dir = C:Program FilesCommon FilesSSL/private
default_default_cert_area = C:Program FilesCommon FilesSSL
ini_cafile = 
ini_capath = 

If all good so far, then this bit should work....
fsockopen 
Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in C:Apache24htdocsphptest2.php on line 28

Warning: fsockopen(): Failed to enable crypto in C:Apache24htdocsphptest2.php on line 28

Warning: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) in C:Apache24htdocsphptest2.php on line 28
bool(false) int(0) string(0) "" 

第 28 行是这一行 var_dump(fsockopen("ssl://smtp.gmail.com", 465, $errno, $errstr, 3.0));

Line 28 is this line var_dump(fsockopen("ssl://smtp.gmail.com", 465, $errno, $errstr, 3.0));

再次感谢

更新 #2

我只搜索了fsockopen():SSL 操作失败,代码为 1".第一个警告.

I googled just "fsockopen(): SSL operation failed with code 1." of the first warning.

这里结束.我改变了AVG的邮件端口,就像答案一样.symcbean 的代码运行没有错误,但我的代码回复了mail error : authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please login through your web browser and 5.7.14 then try again. 5.7.14 在 5.7 了解更多.14 https://support.google.com/mail/answer/78754 c1sm1243434wre.84 - gsmtp)]

End up here . I changed the mail port of the AVG, like the answer. symcbean's code run with no errors, but my code replied with mail error : authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please log in via your web browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 c1sm1243434wre.84 - gsmtp)]

所以我用谷歌搜索了 code: 534, response: 5.7.14 并最终得到 here,按照 emgh3i 的第一个答案的说明,启用安全性较低的连接并允许访问我的谷歌帐户

So I googled code: 534, response: 5.7.14 and end-up here, followed the instructions of the first answer by emgh3i, enabled less secured connections and allowed access to my google account

它现在工作得很好.

推荐答案

"本指南的使用 Gmail SMTP 服务器" 部分指出您需要启用安全性较低的应用".

这篇关于PEAR 邮件无法连接到 Gmail SMTP,无法连接到套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆