1

For some reason mail() function fails when we try to send emails, I debugged the Magento base code and I found that it generates a call to mail function like this:

$result = mail('[email protected]', 'My Test Message', "I'm sending a test message",  $header, '-f');

I tested this in a simple PHP page and in fact it doesn't work, that's weird because I debugged the same Magento code in our old server and the call is the same and there the mail function works as expected.

In order to make it work I tried to remove the last parameter and then the email is sent

$result = mail('[email protected]', 'My Test Message', "I'm sending a test message",  $header);

and also I tested the next and the email is sent too

$result = mail('[email protected]', 'My Test Message', "I'm sending a test message",  $header, '-f [email protected]');

So I don't know why the magento call is not working, I think it's related to the server configuration or PHP configuration because the same call works as expected in our old server, but I'm not sure.

Our old server was Windows Server and now we're over Ubuntu server and my PHP v5.5.9.

I was searching for information and I found that the flag this in the release notes for 1.9 version

UPDATE I received information from one of the technical guy and now I know that the server is using postfix to send emails. This is a log that I received:

Jun 17 15:39:58 web01 postfix/sendmail[21502]: fatal: usage: sendmail [options]
Jun 17 15:41:07 web01 postfix/sendmail[21697]: fatal: usage: sendmail [options]
9
  • Maybe it works, but gets into spam folder?
    – Amasty
    Commented Jun 17, 2016 at 18:36
  • @Amasty No they are not in the spam, the mail function fails, it returns false so any email is sent Commented Jun 17, 2016 at 18:43
  • What does the server's mail log say? Commented Jun 17, 2016 at 20:04
  • @NickWeisser I added that information to the question, the server is using postfix to send emails instead of sendmail Commented Jun 17, 2016 at 20:09
  • If the time stamp matches with your test then the message seems to be sent correctly, but the from header is not a real email address so it's probably being classified as spam by the receiving server. So it's not a Magento problem, but a mail server configuration problem. Commented Jun 17, 2016 at 20:17

1 Answer 1

2

I think the problem is not in Magento itself, but is in between PHP and your OS. I'm going to try to answer it anyway.

The PHP mail() function accepts the following arguments (from PHP.net/mail):

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

So the difference is in the last parameter, as I understand. This last parameter is passed down your mail sending program as additional command line parameter directly. This explains why this PHP code could work on one machine, but not on the other.

Check the logs of your mail program, probably sendmail on Ubuntu. Sendmail accepts the from parameter in the form of -f name. So setting it as -f without a name would probably not work.

You could also try one of the other StackExchange websites that are more ontopic on this part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.