CodeIgniter电子邮件抛出错误

时间:2017-12-11 07:12:08

标签: php codeigniter email

我无法使用CodeIgniter发送邮件。它显示以下错误。

TOC_INCLUDE_HEADINGS

我在 email.php 库中的设置

fwrite(): send of 28 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.

我可以发送电子邮件直到昨天。但从今天早上起,它显示了这个错误 更新: 我已将主机更改为public $useragent = 'CodeIgniter'; public $mailpath = '/usr/sbin/sendmail'; // Sendmail path public $protocol = 'smtp'; // mail/sendmail/smtp public $smtp_host = 'smtp.mailhostbox.com'; public $smtp_user = 'xxx@xx.in'; public $smtp_pass = 'xxxxxx'; public $smtp_port = 25; public $smtp_timeout = 5; public $smtp_keepalive = FALSE; public $smtp_crypto = ''; public $newline = "\r\n"; ,但仍无效。以下是我所做的更改

gmail

但它显示错误为
public $useragent = 'CodeIgniter'; public $mailpath = '/usr/sbin/sendmail'; // Sendmail path public $protocol = 'smtp'; // mail/sendmail/smtp public $smtp_host = 'smtp.gmail.com'; public $smtp_user = 'noreply.xxx@gmail.com'; public $smtp_pass = 'xxxxxx'; public $smtp_port = 465; public $smtp_timeout = 5; public $smtp_keepalive = FALSE; public $smtp_crypto = 'ssl'; public $newline = "\r\n";

我将端口从465更改为587,如下所示

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465:465 (Failed to parse address "smtp.gmail.com:465:465")

但是我收到了这个错误

public $smtp_port = 587; public $smtp_crypto = 'tls';

我无法理解真正的问题是什么,因为它会在每种可能的情况下抛出错误

1 个答案:

答案 0 :(得分:1)

您需要初始化配置。see here

例如

function send_email($attributes) {

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

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

        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'host';
        $config['smtp_port'] = '465';
        $config['smtp_user'] = 'user@smtp.com';
        $config['smtp_from_name'] = 'FROM NAME';
        $config['smtp_pass'] = 'XXX';
        $config['wordwrap'] = TRUE;
        $config['newline'] = "\r\n";
        $config['mailtype'] = 'html';                       

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

        $this->email->from($config['smtp_user'], $config['smtp_from_name']);
        $this->email->to($attributes['to']);
        $this->email->cc($attributes['cc']);
        $this->email->bcc($attributes['cc']);
        $this->email->subject($attributes['subject']);

        $this->email->message($attributes['message']);

        if($this->email->send()) {
            return true;        
        } else {
            return false;
        }       

}