Codeigniter不发送带有smtp设置的电子邮件

时间:2015-11-04 10:32:59

标签: php codeigniter

我在config文件夹中有email.php:

$config = Array(
    'protocol' => 'tls',
    'smtp_host' => 'mail.lifepro.ro',
    'smtp_port' => 465,
    'smtp_user' => 'office@lifepro.ro',
    'smtp_pass' => 'xxxxxxxxxxxx',
    'mailtype' => 'html',
    'charset' => 'utf-8',
    'wordwrap' => TRUE
);

和帮助中的这个功能

    function email_send($to, $subject, $body) {

        $ci = get_instance();
        $ci->email->from('office@lifepro.ro', 'Office LifePro');
        $ci->email->to($to);
        $ci->email->cc('office@lifepro.ro');

        $ci->email->subject($subject);
        $ci->email->message($body);

        if($ci->email->send())
            return true;
    }

问题是,即使我输入了错误的凭据,CI也会发送电子邮件。为什么会这样?我知道config文件夹中的email.php是自动加载的。

3 个答案:

答案 0 :(得分:1)

您无需在电子邮件库中使用此功能

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

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  

if(!$this->email->send())
{
    echo $this->email->print_debugger();
}
else
{
    echo "Sent"
}

Email Class

答案 1 :(得分:0)

解决

'protocol' => 'smtp'

答案 2 :(得分:0)

$config = Array(
    'protocol' => 'smtp',
    'smtp_crypto' => 'tls', //         <--- notice
    'smtp_host' => 'mail.lifepro.ro',
    'smtp_port' => 465, //             <--- or 587
    'smtp_user' => 'office@lifepro.ro',
    'smtp_pass' => 'xxxxxxxxxxxx',
    'mailtype' => 'html',
    'charset' => 'utf-8',
    'wordwrap' => TRUE
);