【问题标题】:SMTP ERROR: Failed to connect to server: Permission denied (13)SMTP 错误:无法连接到服务器:权限被拒绝 (13)
【发布时间】:2015-11-27 05:53:14
【问题描述】:

美好的一天!

我试图让我的 phpmailer 在我的共享主机 (freehostia.com) 中工作,但我总是收到此错误。我的gmail的用户名和密码是正确的,剩下的设置是这样的:

$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 中也没有注释。我在这里错过了什么吗?谢谢。

完整的错误信息:

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

【问题讨论】:

标签: php smtp phpmailer


【解决方案1】:

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

$ getsebool httpd_can_sendmail

如果显示:httpd_can_sendmail --> off

用这个打开它:

$ sudo setsebool -P httpd_can_sendmail 1

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

这个解决方案来自这个伟大的page

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

我遇到的问题是无法从 Drupal 网站发送电子邮件,其中 SMTP 身份验证支持模块依赖于底层的 PHPMailer。使用的 SMTP 服务器是 Google。

顺便说一句,我怀疑这是 OpenSSL 证书问题并做了一些测试但没有运气。因此,通过将 PHPMailer 源代码中的$SMTPDebug 级别设置为 2,我能够捕获“Permission denied (13)”错误消息。

【讨论】:

  • 非常感谢您的回答,我希望我能多次投票。
【解决方案2】:

这表明在您的 PHP 安装中禁用了 fopen 包装器或套接字函数。在共享主机中并不罕见。运行phpinfo() 应该会告诉你。

您可能可以使用$mail->isMail(); 并跳过身份验证以通过 ISP 的邮件服务器而不是 SMTP 发送,但要注意 SPF 问题。

【讨论】:

  • 你帮了我很多。
【解决方案3】:
use this
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "ssl://smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port

如果这不起作用,请尝试下面的 php 代码。

邮件($to,$subject,$message);

【讨论】:

  • 试试这个 $mail->SMTPDebug = 0; // 1 启用 SMTP 调试(用于测试),0 禁用调试(用于生产)
  • 您好,亲爱的,您的 phpmailer 类文件不是正确的代码。所以请找到正确的class.phpmailer.php
【解决方案4】:

问题在于 freehostia 的免费托管会阻止外发邮件。

【讨论】:

    【解决方案5】:

    Freehostia 在免费计划中阻止以下列表。 (巧克力)

    -邮件程序

    -卷曲

    -肥皂获取

    -xml获取

    【讨论】:

      【解决方案6】:

      这对http很重要

      • getsebool httpd_can_sendmail 已关闭然后打开它 sudo setsebool -P httpd_can_sendmail 1
      • 可能需要 sudo 'setsebool -P httpd_can_network_connect 1'
      • disable_function = ...... 删除 php.ini 中 exec() 的 exec

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-29
        • 1970-01-01
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 2011-04-28
        • 2014-12-06
        • 1970-01-01
        相关资源
        最近更新 更多