首页 > 解决方案 > fsockopen():无法连接到 ssl://smtp.gmail.com:465(权限被拒绝)

问题描述

遇到 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");

标签: codeigniternginxcentosphpmailer

解决方案


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

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


推荐阅读