Welcome Guest, Not a member yet? Register   Sign In
Can't send mails with mail() function
#1

Hello!
I was just trying to send my mails with CI3 with default mail() function, but getting an error

(German) Die E-Mail konnte mit PHP mail() nicht gesendet werden. Ihr Server ist offenbar nicht konfiguriert, um mit dieser Methode E-Mails zu versenden.
(Translated) The email could not be sent with with PHP mail(). Your server is apparently not configured to send e-mails using this method.

Strange thing, that if i use pure mail() function without CI3, it works! I was following down the error and found in Email library.
The function
PHP Code:
protected function _send_with_mail()
 {
 if (
is_array($this->_recipients))
 {
 
$this->_recipients implode(', '$this->_recipients);
 }

 if (
$this->_safe_mode === TRUE)
 {
 return 
mail($this->_recipients$this->_subject$this->_finalbody$this->_header_str);
 }
 else
 {
 
// most documentation of sendmail using the "-f" flag lacks a space after it, however
 // we've encountered servers that seem to require it to be in place.
 
return mail($this->_recipients$this->_subject$this->_finalbody$this->_header_str'-f '.$this->clean_email($this->_headers['Return-Path']));
 }
 } 

As you can see, there is a check if PHP is running in safe mode, if no, use this:
PHP Code:
return mail($this->_recipients$this->_subject$this->_finalbody$this->_header_str'-f '.$this->clean_email($this->_headers['Return-Path'])); 
And that doesn't work! The fifth parameter is one which breaks sending mails. If i remove it, it works.

My server is running with Debian 7.8 and latest php-fpm and sendmail. Is there some solution not to touch the core library?
Reply
#2

In pure php did you try to send an email using a fifth parameter and it worked? http://php.net/manual/en/function.mail.php
Reply
#3

So, was trying right now. Fifth parameter is not being accepted at all by PHP 6.8 and latest sendmail from apt-get.
Some reconfiguration of them required?
Reply
#4

So, okay. I found the problem. For anyone wh might have the same trouble, here is solution.
My server's php was configured to send mails already with the "-f" flag in php.ini.
So it was:
sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]

Just remove -f w[email protected] so it will look like "sendmail_path = /usr/sbin/sendmail -t -i" and enjoy! Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB