could not execute usr sbin sendmail

I try to send an email via phpmailer and this is my code:

And I get this error:

Could not execute: /usr/sbin/sendmail -t -i

Any ideea why I get this error and why the email is not sending ?

I also contacted the company and they told me that sendmail is active and they even did a apache restart for me but I still get the same error. They told me that I should set a host mail.mydomain.ro in order to work, but in the phpmailer example I don’t have any host to set.

UPDATE: In case I try to use SMTP I get this error:

2 Answers 2

Why are you using isSendmail() at all? You should only need it if you have a weird, customised sendmail emulation that requires more control over it than mail() provides; it’s mainly there for historical reasons from back when that was more common (PHPMailer has been around since 2001!).

If you simply do nothing, PHPMailer defaults to using PHP’s built-in mail() function. However, I’d recommend you avoid that and use isSMTP() anyway — it’s more reliable, faster, more secure, and provides better feedback on sending. If mail() works, all it should involve is adding:

Leaving everything else with defaults should be fine. This is significantly less hassle than customising a sendmail config.

Also, you’re not helping yourself by not setting Body — that may be the cause of your error. If you want to send a plain-text-only message, do this:

Why? I can send via mail() in PHP but I can’t send via PHPMailer using IsSendmail()

7 Answers 7

Are you sure the path /usr/sbin/sendmail is correct?

If yes, check also the permissions for sendmail are set correctly.

I’ve had the same error. Solved it by commenting/deleting this:

Now it works correctly. I can send mails, and I receive them in my inbox.

I had this same issue. Spent almost an hour checking logs, checking sendmail paths and testing php mail() and sendmail from command line to no avail. And finally all I did was restarted Apache using apachectl -k graceful and the universe was healed.

For me it’s working with $mail->IsSMTP() . IsSendmail() is looking for sendmail.

I agree with the bloc above. The default mail() function is enabled on all servers (i believe). In my case I was able to send basic html using the simple mail() function but when I used PHPMailer to do that I had that error.

So I removed the part where it checks i.e. IsSendMail() and all was fine. Now more exception thrown.

For people who want to use SMTP. First create an email account on your sever and then define its parameter in your code.

Появилась на продакшен сервере вот такая ошибка

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

Код в этом файле такой:
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, «-f «.$this->clean_email($this->_headers[‘From’]))) < return FALSE; >else

Чтобы отловить ошибку пробовал ловить exception его нет
try < тут код с майл; >catch (Exception $e) < print $e->getMessage(); > return true;

Вывел echo все переменные на продакшене и на тестовом, вроде тут тоже все одинаковое.

Код одинаковый с тестовым сервером, на тестовом такое же окружение в такой же ос(amazon linux аналог centos) все работает и шлет. Изменений в момент когда все сломалось в окружение я не вносил.

Файл /usr/sbin/sendmail присутствует, имеет нормальные права и нормально запускается.

Функция mail используется в других частях кода и там все в порядке.
В php.ini всего две строчку для настройки mail
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On

Пробовал убирать -t -i для теста, чтобы проверить используется ли этот php.ini, после этого ошибка изменилась на не могу вызвать sendmail но без параметров -t -i

Скрипт запускаю в консоли, memory_limit 1500MB, памяти свободной куча, проца тоже, файл подкачки пустой.

конфиг php.ini не менялся несколько месяцев, конфиг sendmail также не менялся несколько месяцев.

Обновил для пущей уверенности php до 5.3.25 и sendmail до 8.14.4
Ума не приложу в какую сторону копнуть ещё или как получить больше информации об ошибке.

Оцените статью