【问题标题】:Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Permission denied)消息:fsockopen():无法连接到 ssl://smtp.googlemail.com:465(权限被拒绝)
【发布时间】:2018-09-16 07:40:41
【问题描述】:

从 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

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

我该如何解决这个问题?

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

感谢您的宝贵时间。

【问题讨论】:

    标签: php linux codeigniter email vps


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      • 端口 25

      .

      【讨论】:

      • 请提供一些解释如何回答这个问题
      • 如果 smpt 端口不工作,smtp 发送邮件将失败。因此,请确保您的防火墙允许端口 25 上的流量,或者您用于 smtp 的任何端口。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-08
      • 2020-12-31
      • 2016-11-07
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多