Answer the question
In order to leave comments, you need to log in
Problem sending mail via mail() in php
The following error appeared on the production server
: Severity: Warning
Message: mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i'
Filename: libraries/Email.php
Line Number: 1545
framework code igniter
Code in This file is as follows:
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
{
return FALSE;
}
else
{
return TRUE;
}
To catch an error, I tried to catch an exception; it is not present.
try {
тут код с майл;
}
catch (Exception $e)
{
print $e->getMessage();
}
return true;
I echoed out all the variables on the production and on the test, everything seems to be the same here too.
The code is the same with the test server, on the test server the same environment in the same OS (amazon linux analogue of centos) everything works and sends. I did not make changes at the time when everything broke into the environment.
The file /usr/sbin/sendmail is present, has normal permissions and starts normally.
The mail function is used in other parts of the code and everything is fine there.
There are only two lines in php.ini for setting mail
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
I tried to remove -t -i for a test to check if this php.ini is used, after that the error changed to I can't call sendmail but without parameters -t -i I
run the script in the console, memory_limit 1500MB, there is a lot of free memory, the processor too, the paging file is empty.
the php.ini config hasn't changed in months, the sendmail config hasn't changed in months either.
I updated php to 5.3.25 and sendmail to 8.14.4 just to be sure
.
Answer the question
In order to leave comments, you need to log in
Exception will not be there.
Simplify the code to
return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']));
mail()
works in other places, then the problem is most likely in the parameters. Try hardcoding for a test. /var/log/maillog
/var/log/mail.*
To find out exactly the problem in sendmail or php, try calling sendmail from the console, and send some test email manually. If it goes, then the problem is in php. If it doesn’t send, either you will immediately find out what the error is, or look in the sendmail settings, because the problem could have appeared due to a change in the requirements for sending letters at the gateway (through which sendmail itself is sent). Again, you need to try to send to different hosts.
In general, use PHPMailer
I would still add From: to the headers, and not as a separate parameter to sendmail.
Make var_dump
absolutely all the parameters that are passed to sendmail ( $this->_recipients
etc.) and try to run from php, then from the console mail()
with exactly the same parameters. If you catch an error again, play around with the parameters and find the problematic one. If it sends, then check from which user it is launched php (var_dump(exec('whoami')))
, then try to send from it ( su username
).
Did you find out what the problem is? The same thing happens on AWS, I can not win in any way =(
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question