无法发送没有"发件人"标题的邮件

Dan*_*iel 0 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';
        }
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

 Cannot send mail with no "From" header.
Run Code Online (Sandbox Code Playgroud)

Sat*_*aty 6

在您的代码中,您已使用过$this->email->send(),然后再$this->email->send()在if语句中使用.发送电子邮件后,图书馆会清除所有内容.因此,如果您想在出现错误时执行某些操作,则不要执行相同的方法两次:

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

} 
Run Code Online (Sandbox Code Playgroud)