【问题标题】:Codeigniter send google mail errorCodeigniter 发送谷歌邮件错误
【发布时间】:2014-01-18 03:00:36
【问题描述】:

我在主机 Cpanel 中使用 Codeignter。在本地我可以通过谷歌帐户发送电子邮件,但在主机 Cpanel 上它会出错。 这是我的配置:

$ci = get_instance();

$ci->load->library('email');

$config['protocol'] = "smtp";

$config['smtp_host'] = "ssl://smtp.gmail.com";

$config['smtp_port'] = 465;

$config['smtp_user'] = "xxx@gmail.com"; 

$config['smtp_pass'] = "xxx";

$config['charset'] = "utf-8";

$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

在主机上启用 Openssl。

这是错误提示:

.....
Message:  fsockopen() ...: unable to connect to ssl://smtp.gmail.com:465 
.....

请帮帮我! 对不起,我的英语不好

【问题讨论】:

    标签: php codeigniter email ssl


    【解决方案1】:

    #1确保您在 Apache 中有 ssl_module,在 php.ini 中有 allow_url_fopen 打开或启用。

    #2确保您在 gmail 设置中启用了 POP3

    #3 如果您在启用代理或防火墙的网络中工作;确保您已打开所需的 PORT (465)。

    试试这个自我测试的代码。

    $config['useragent']    = 'CodeIgniter';
    $config['protocol']     = 'smtp';
    $config['smtp_host']    = 'ssl://smtp.googlemail.com';
    $config['smtp_user']    = '*****developer@gmail.com'; // Your gmail id
    $config['smtp_pass']    = '**********'; // Your gmail Password
    $config['smtp_port']    = 465;
    $config['wordwrap']     = TRUE;    
    $config['wrapchars']    = 76;
    $config['mailtype']     = 'html';
    $config['charset']      = 'iso-8859-1';
    $config['validate']     = FALSE;
    $config['priority']     = 3;
    $config['newline']      = "\r\n";
    $config['crlf']         = "\r\n";
    
    $this->load->library('email');
    $this->email->initialize($config);
    
    $this->email->from('trimantradeveloper@gmail.com', 'TSS DEV');
    $this->email->to('trimantra@trimantra.com'); 
    $this->email->cc('trimantra@gmail.com'); 
    
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');    
    
    $this->email->send();
    

    【讨论】:

      【解决方案2】:
      $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'xxx',
      'smtp_pass' => 'xxx',
      'mailtype'  => 'html', 
      'charset'   => 'iso-8859-1'
      );
      $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      
      // Set to, from, message, etc.
      
      $result = $this->email->send();
      

      【讨论】:

      • 感谢帮助!我会尝试这种方式,但它也不适合我。我在谷歌搜索了很多但没有解决方案
      【解决方案3】:

      确保您的服务器的 apache 已启用 ssl 模块。很可能这可能是原因。或者您可以采取其他方式。检查删除 google 的 smtp ssl 方法。如果您这样做,您想更改 smtp 端口表格 465 至 587

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-02
        • 2017-11-10
        • 2015-03-17
        • 2016-05-06
        • 1970-01-01
        • 1970-01-01
        • 2016-09-02
        相关资源
        最近更新 更多