无法发送没有" From"头

时间:2015-06-05 09:10:08

标签: php codeigniter

我收到此错误帮助!我试图发送电子邮件,但它无法正常工作

        $this->email->from('you@example.com', 'Your Name');
        $this->email->to($data['email']);
        $this->email->subject('This the test');
        $this->email->message('this is the test message');

        $this->email->send();

        if(! $this->email->send()){

            echo $this->email->print_debugger();
        }

        else
        {
            echo 'send';
        }

我收到此错误

 Cannot send mail with no "From" header.

2 个答案:

答案 0 :(得分:5)

在您的代码中,您已使用$this->email->send(),然后再在if语句中使用$this->email->send()。发送电子邮件后,图书馆会清除所有内容。所以,如果你想在出现错误的情况下做某事,你就不要两次做同样的方法:

 $this->load->library('email');
        $this->email->from('you@example.com', 'Your Name');
        $this->email->to($data['email']);
        $this->email->subject('This the test');
        $this->email->message('this is the test message');
// $this->email->send(); don't do this and then the same thing!

 if (!$this->email->send())
{    
echo $this->email->print_debugger();

} 

答案 1 :(得分:0)

另外,请确保任何初始化代码,例如

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

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

在您设置之前,之后,等等。