ToddBFisher
ToddBFisher

Reputation: 11610

PHP mail: What does -f do?

While troubleshooting a contact form with an e-mail host they told me to use '-f' in the from address of the php mail function. What does the "-f" flag do and why would that be a fix for allowing an e-mail to be delivered? I read some of the documentation but I'm not quite clear on it.

Example code:

mail($emailAddress, $mailSubject, $mailBody, $headers, '-f ' . $mailFrom);

PS: without the "-f" it works just fine for the big e-mail hosts (hotmail, gmail, etc, but for whatever reason not for the smaller host I'm working with)

Thanks

Upvotes: 15

Views: 13629

Answers (3)

11mb
11mb

Reputation: 1359

The -f option is to set the bounce mail address. Sending a message without one can negatively influence the spam-score that is being calculated over the message. Messages with low scores sometimes get filtered out for certain hosts.

You can use https://www.mail-tester.com/ to test the score of your message. You can expirement with or without the -f flag and see the score change.

Upvotes: 5

thoaionline
thoaionline

Reputation: 524

It is a flag to mark the following text ($mailFrom) to be used as "from" address of the mail.

Have a look at: http://www.php.net/manual/en/function.mail.php

Upvotes: 3

nickb
nickb

Reputation: 59709

-f is a parameter to the mailer (usually sendmail). From the docs:

The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

Here is the man page for sendmail, you can see what the -f option does:

-fname           Sets the name of the ``from'' person (i.e., the sender of the
                 mail).  -f can only be used by ``trusted'' users (normally
                 root, daemon, and network) or if the person you are trying to
                 become is the same as the person you are.

Upvotes: 12

Related Questions