Unable to send email using SendmailMailer in v4.0.2
Version: 4.0.2
Bug Description
I have very simple code to send email using SendmailMailer. Everything is working in nette/mail v3.1.11. When I upgrade to nette/mail v4.0.2 there is error:
Nette\Mail\SendException - Unable to send email
Steps To Reproduce
Try this code with nette/mail v3.1.11 (working) and with v4.0.2 (not working)
$mail = new Nette\Mail\Message;
$mail->setFrom('Franta <[email protected]>')
->addTo('[email protected]')
->setSubject('Potvrzení objednávky')
->setBody("Dobrý den,\nvaše objednávka byla přijata.");
$mailer = new Nette\Mail\SendmailMailer;
$mailer->send($mail);
It seems to me, that the problem is on line SendmailMailer.php on line 52 - after removal it work ok.
$cmd .= ' -f' . key($from);
Expected Behavior
Code is working with both versions (v3.1.11 and v4.x.x)
Related to #78
Setting an envelope address (-f $from) is correct from more points of view.
- receiving MTA puts this address into message as a
Return-Pathheader and uses it for bounce messages (mailbox full, mailbox does not exist, ...) - receiving MTA uses envelope address for SPF policy evaluation (not sure it's standard, at least GMail does it) which is todays quite important
@zabous Your problem can be on more levels. Default PHP sendmail command is sendmail_path = sendmail -t -i. Maybe your hosting modified it, should be seen in php info.
The sendmail command is quite UNIX standard and many non-sendmail MTA emulates it. Maybe it is not full compatible.
Or sending MTA does not allow $from to be envelope address. Such error could be found in mail log, not sure you can access it.
I see my phpinfo() that "sendmail_path" on my hosting is set to "/usr/bin/msmtp -C /etc/msmtprc -t --read-envelope-from" It works fine without ' -f' param. @milo is there some problem in this setting?
I cannot access mail log - should I try to ask my provider for my mail logs?
From msmtp man page, parameter --read-envelope-from ensures same behaviour. I cannot test it but probably additional -f is evaluated as an error.
This is hard to solve in some automatic way. Anyway, I think passing -f is correct in most cases. Possible solutions in my mind:
- add
SendmailMailer::setEnvelopeFrom(bool)or introduce__construct()params - somehow detect it from
sendmail_pathINI setting, but there are many sendmail clones
Or you can try to use SmtpMailer, there will be probably available localhost:25 SMTP connection.
Parameter -f is correct in most cases? I'm afraid that's not enough for general library.
In my opinion, it is better to leave the -f parameter to the developer using the library.
Thanks for the advice with SendmailMailer::setEnvelopeFrom(bool). That can be helpful, but I cannot find this function in SendmailMailer.
Is there another way to turn off adding the -f parameter?
Parameter
-fis correct in most cases? I'm afraid that's not enough for general library. In my opinion, it is better to leave the-fparameter to the developer using the library.
Yes. It is correct to set envelope address to From header.
Thanks for the advice with
SendmailMailer::setEnvelopeFrom(bool). That can be helpful, but I cannot find this function in SendmailMailer.
It is only an idea how to solve it by pull request.
Is there another way to turn off adding the
-fparameter?
No. Send pull request with explanation.