SMTP错误:无法连接到服务器:权限被拒绝(13) [英] SMTP ERROR: Failed to connect to server: Permission denied (13)

查看:130
本文介绍了SMTP错误:无法连接到服务器:权限被拒绝(13)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我试图让我的phpmailer在共享托管(freehostia.com)中工作,但我总是收到此错误.我的gmail用户名和密码正确,其余设置如下:

Im trying to make my phpmailer work in my shared hosting (freehostia.com) and I always get this error. The username and password of my gmail is correct, and the rest of the settings is like this:

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug  = 2;
$mail->Host       = 'tls://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth   = true; // Enable SMTP authentication
$mail->Username   = 'mymail@gmail.com'; // SMTP username
$mail->Password   = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port       = 587; // TCP port to connect to

$mail->setFrom('mymail@gmail.com', 'ASAPHOT Administrator'); // Add a recipient
$mail->addAddress('sorianorobertc@gmail.com'); // Name is optional
$mail->addReplyTo('mymail@gmail.com', 'ASAPHOT Administrator');

$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'it works';
$mail->Body    = 'it works';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if (!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

openssl也未在php.ini中注释.我在这里想念什么吗?谢谢.

openssl is uncommented in the php.ini also. Am I missing something here? Thank you.

完整的错误消息:

Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Permission denied (13)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

推荐答案

让我们首先获得答案!尝试使用以下命令:

Let's get to the answer first of all! Try with the following command:

$ getsebool httpd_can_sendmail

如果显示:httpd_can_sendmail --> off

为此打开它:

$ sudo setsebool -P httpd_can_sendmail 1

然后尝试再次发送电子邮件.

then try sending the email again.

此解决方案来自于出色的页面.

This solution comes from this great page.

如本文所指出,您可能还需要尝试sudo setsebool -P httpd_can_network_connect 1.对于由DigitalOcean托管的CentOS 7虚拟机,这不是必需的.

As it was pointed out from this article, you may also need to try sudo setsebool -P httpd_can_network_connect 1. While for my CentOS 7 vm hosted by DigitalOcean, it's not necessary.

我遇到的问题是无法从Drupal网站发送带有SMTP身份验证支持模块的电子邮件,该模块依赖于下面的PHPMailer.所使用的SMTP服务器是Google.

The problem I met was failing to send out emails from a Drupal website, with the SMTP Authentication Support module, which relies on PHPMailer underneath. And the SMTP server used was Google.

顺便说一句,我怀疑这是OpenSSL证书问题,做了一些测试,但是没有运气.因此,通过将PHPMailer源代码中的$SMTPDebug级别设置为2,我可以捕获权限被拒绝(13)"错误消息.

BTW, I had suspected it was OpenSSL certificate problem and did some test but no luck. So by setting the $SMTPDebug level to 2 from the PHPMailer source code, I was able to capture the "Permission denied (13)" error message.

这篇关于SMTP错误:无法连接到服务器:权限被拒绝(13)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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