消息:fsockopen():无法连接到ssl://smtp.googlemail.com:465(权限被拒绝)

时间:2018-09-16 07:40:42

标签: 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_port 465 更改为 587 25 。它仍然是相同的错误。

我该如何解决?

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

感谢您的时间。

2 个答案:

答案 0 :(得分:0)

我尝试这个,对我来说很有效。 我希望它也对您有用

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

答案 1 :(得分:0)

我的建议是检查端口,确保服务器防火墙允许 smtp 。 您可能需要检查

  • 端口25

相关问题