【问题标题】:config email library for send email in codeigniter配置电子邮件库以在 codeigniter 中发送电子邮件
【发布时间】:2016-11-02 09:29:03
【问题描述】:

我在控制器 codeigniter 框架中有如下代码:

class Welcome extends CI_Controller {
public function index()
{
    $this->load->view('welcome_message');

    $this->load->library('email'); 
    $this->email->from('example@yahoo.com', 'example');
    $this->email->to('example@gmail.com','example');
    $this->email->subject('my Subject');
    $this->email->message('my Message');

    if ($this->email->send())
        echo "Mail Sent!";
    else
        echo "There is error in sending mail!";    
    }
}

此代码正确发送电子邮件。但是当我配置电子邮件类设置时,此代码不起作用并且不发送电子邮件。例如跟随代码不会发送电子邮件:

class Welcome extends CI_Controller {
public function index()
{
    $this->load->view('welcome_message');

    $this->load->library('email'); 
    $this->email->from('example@yahoo.com', 'example');
    $this->email->to('example@gmail.com','example');
    $this->email->subject('my Subject');
    $this->email->message('my Message');

    $config['protocol'] = 'sendmail';
    $config['charset'] = 'iso-8859-1';
    $config['wordwrap'] = TRUE;
    $this->email->initialize($config);

    if ($this->email->send())
        echo "Mail Sent!";
    else
        echo "There is error in sending mail!";    
    }
}

请告诉我问题出在哪里。 谢谢。

【问题讨论】:

  • 您是否尝试使用SMTP 协议发送邮件?

标签: codeigniter email send


【解决方案1】:

协议可以是SendmailSMTPmail

你应该在配置后加载库:

$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");

$this->email->from('example@yahoo.com', 'example');
$this->email->to('example@gmail.com','example');
$this->email->subject('my Subject');
$this->email->message('my Message');

if ($this->email->send())
{
    echo "Mail Sent!";
}
else
{
    echo "There is error in sending mail!";    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-08
    • 2017-12-07
    • 2013-01-07
    • 2019-08-07
    • 1970-01-01
    • 2015-09-06
    • 2016-03-10
    • 2014-07-13
    相关资源
    最近更新 更多