php - 消息 : fsockopen(): unable to connect to ssl://smtp. googlemail.com:465(权限被拒绝)

标签 php linux codeigniter email vps

从 VPS 发送电子邮件失败。它在我的本地主机上运行良好,但在实时服务器上运行不正常。我的代码如下。

   $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'my gmail email',
        'smtp_pass' => 'email password',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
    );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

    $this->email->from('from-email', 'name');
    $this->email->to('to-email');
    $this->email->subject('Hello Test');
    $this->email->message('Hello Message');
    if ($this->email->send()) {
        echo 'send';
    }else {
        show_error($this->email->print_debugger());
    }

它在 localhost 中运行良好。 在我的 VPS 服务器中,它显示错误。

A PHP Error was encountered
Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Permission denied)

Filename: libraries/Email.php

Line Number: 1990

Backtrace:

File: /var/www/html/company/application/controllers/Welcome.php
Line: 46
Function: send

File: /var/www/html/company/index.php
Line: 315
Function: require_once

Error screenshot from browser

我还将我的 smtp_port465 更改为 58725。它仍然是相同的错误。

我该如何解决?

谁能告诉我,如何检查服务器的 465 端口是否打开? 我的VPS服务器操作系统是:centos

感谢您的宝贵时间。

最佳答案

我试试这个,它对我有用。 我希望它也适合你

$config['protocol'] = 'smtp';
$config['smtp_crypto'] = 'tls';
$config['smtp_host'] = 'smtp.gmail.com';    
$config['smtp_port'] = '587';

关于php - 消息 : fsockopen(): unable to connect to ssl://smtp. googlemail.com:465(权限被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52352012/

相关文章:

jquery - jQuery ajax 方法出错并且页面刷新

php - 在 php 中发布复选框值

php - jQuery 淡出由 php 而不是 Javascript 显示的 div?

php - 获取变量内容并将变量剥离为仅返回数字的函数

linux - 如何将 python 脚本转换为 python 中的可执行文件?

c - switch_root 和 run_init 有什么区别?

php - UTF-8 符号显示错误

javascript - 使用 jquery 从 ul li 获取 id

php - 要求 FTP 的 WordPress 插件更新

linux - 无法在 VirtualBox Debian 8 中访问 Ajenti Web 面板端口