【问题标题】:fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Permission denied)fsockopen():无法连接到 ssl://smtp.gmail.com:465(权限被拒绝)
【发布时间】:2020-07-15 16:22:42
【问题描述】:

遇到 PHP 错误 严重性:警告 消息:fsockopen(): 无法连接到 ssl://smtp.gmail.com:465(权限被拒绝)

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'user',
    'smtp_pass' => 'password',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

【问题讨论】:

  • 上面的代码在我的子域上也适用于我的本地主机,但不适用于我的 aws lightail :(

标签: codeigniter nginx centos phpmailer


【解决方案1】:

如果您正在运行 Red Hat 衍生产品,它们默认启用 SELinux,并且可能php-fpm 被拒绝访问创建套接字。尝试通过运行grep php /var/log/audit/audit.log | grep denied 来检查它。

如果是这样,您可以以 root 身份运行/usr/sbin/setsebool httpd_can_network_connect 1,然后尝试再次运行代码。

【讨论】:

  • 上面的代码在我的子域上也适用于我的本地主机,但不适用于我的 aws lightail :(
  • 以 root 身份运行 [ -f "/etc/redhat-release" ] && getsebool httpd_can_network_connect,并显示输出。
  • 附加 -P 标志以使更改在重新启动时保持不变。 /usr/sbin/setsebool -P httpd_can_network_connect 1.
【解决方案2】:

尝试将您的 EMAIL_SMTP_HOST 定义为

define("EMAIL_SMTP_HOST", "ssl://smtp.gmail.com");

如果碰巧它不起作用,请检查您的 EMAIL_SMTP_PORT,它可能与您在那里设置的不同

define("EMAIL_SMTP_PORT",225O);

最后检查您的 SSL 证书是否安装在您的服务器中,与邮件服务器相同,还要确保您的“SMTP_USERNAME”和“SMTP_PASSWORD”的凭据都正确。

【讨论】:

  • 感谢现在错误没有显示,但我仍然没有收到任何电子邮件
  • @JunaidRaza 你现在可以开始了,现在填写两步验证,,,只需点击本教程链接techstacktutorial.com/… 注意谷歌将在这里给你的密码和你用来登录的电子邮件在两步验证中您将在您的 EMAIL_SMTP 凭证中使用相同的问题,很久以前就有相同的问题,但两步验证解决了它尝试
  • 先查看邮件日志,,,就会有线索知道哪里出错了。试试这个命令 > tail -f /var/log/mail.log
猜你喜欢
  • 1970-01-01
  • 2016-11-07
  • 2020-12-31
  • 1970-01-01
  • 2017-03-13
  • 2017-03-08
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
相关资源
最近更新 更多