CodeIgniter Forums
Cannot send mail with no "From" header. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: Cannot send mail with no "From" header. (/thread-789.html)



Cannot send mail with no "From" header. - mstojanov - 01-18-2015

Hello.

I am using Codeigniter 3 and when i try to send email i get this error
Cannot send mail with no "From" header.
But the email still sends i got them in my mail.

But when i use condition
Code:
if (!$this->email->send())
{
 echo $this->email->print_debugger();
}
It says that cannot send mail with no "From" header but the email stil sends.

My preferences are located in the config/email.php
Here is my code.

     
Code:
$this->load->library('email');
$this->email->from('[email protected]');
$this->email->reply_to('[email protected]');
$this->email->to('[email protected]');
$this->email->subject($this->input->post('emailheading'));
$this->email->message($this->input->post('emailmessage'));
$this->email->set_alt_message($this->input->post('emailmessage'));
$this->email->send();

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

Any help will be appreciated


RE: Cannot send mail with no "From" header. - mstojanov - 01-19-2015

Anyone ?


RE: Cannot send mail with no "From" header. - apparasenal - 01-19-2015

What is the error you are getting?
Can you paste it here so we can take a look.

Thanks.


RE: Cannot send mail with no "From" header. - Avenirer - 01-20-2015

In your code you've already used $this->email->send() before using again $this->email->send() in your if statement. The library, after you send an email, clears everything. So, if you want to do something in case of error you don't do the same method twice:


PHP Code:
$this->load->library('email');
$this->email->from('[email protected]');
$this->email->reply_to('[email protected]');
$this->email->to('[email protected]');
$this->email->subject($this->input->post('emailheading'));
$this->email->message($this->input->post('emailmessage'));
$this->email->set_alt_message($this->input->post('emailmessage'));
// $this->email->send(); don't do this and then the same thing!

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