1

我是 CI 和 PHP 的新手。目前我正在使用 xammp 来运行 PHP、Apache 和 MySql。现在我正在尝试使用 CI 发送电子邮件。但我经常收到如下错误。

遇到 PHP 错误

严重性:警告

消息:fsockopen():无法连接到 ssl://smtp.googlemail.com:465(连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机无法连接回应。 )

文件名:库/Email.php

行号:1689

我用谷歌搜索了大约三个小时,但仍然没有找到解决方案。我已经openssl在 Apache 中启用了“”。我想描述我的电子邮件控制器类的编码。

//电子邮件控制器'索引'函数的代码

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

    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';
    $config['protocol'] = 'smtp';
    $config['smtp_port'] = 465;
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_user'] = "something@gmail.com";
    $config['smtp_pass'] = "xxx";

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

    $this->email->from('something@gmail.com', 'NayLinAung');
    $this->email->to('something@gmail.com');
    $this->email->subject('This is an email test');
    $this->email->message("It is working, Great! You will be successful.");

    if ($this->email->send())
    {
        echo "Email was successfully sent.";
    }
    else {  
        show_error($this->email->print_debugger());
    }

当我将 'smtp' 更改为 'mail' 时,不会发生错误,但实际上并未发送电子邮件。此外,我关闭了我的 Windows 防火墙。

请为此错误提出任何解决方案。

4

2 回答 2

1

我之前发现的是:

要在 CodeIgniter 中使用 Google SMTP,您需要对您的 Gmail 帐户设置进行 2(两)次更改:(请注意,现在攻击者更容易侵入您的帐户 - Google 说)

  1. 启动两步验证
  2. 允许不太安全的应用程序:开(或启用)

现在使用'smtp_host'asssl://smtp.gmail.com而不是smtp.googlemail.com

这个问题也在这个链接中讨论过。

希望这有帮助。

于 2016-01-02T13:04:48.870 回答
0

如果您可以尝试使用此IMAP

Codeigniter Imap 库

你可以用这个代码连接

$config['protocol'] = "imap";
$config['imap_host'] = 'xxx.xxx.xxx.xxx';
$config['imap_user'] = 'user@domain.com';
$config['imap_pass'] = 'Jk98S**Jlk';
$config['imap_port'] = '993';
$config['imap_mailbox'] = 'INBOX';
$config['imap_path'] = '/imap/ssl/novalidate-cert'; // use this string if you do not want use ssl
$config['imap_server_encoding'] = 'utf-8';
$config['imap_attachemnt_dir'] = './tmp/';
$this->load->library('email', $config);
$this->email->from($frommail);
$this->email->to($tomail);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();

您也可以使用SMTP 但如果您有许可,我建议您使用IMAP。它有更多的功能,比SMTP更新...

于 2016-05-08T16:50:53.753 回答