Discussion:
matching return-path domain with virtual hosts
(too old to reply)
R.A. Imhoff
14 years ago
Permalink
Thank you for your suggestions!

I did set the "From: " correctly, both in the php.ini and in the php code that calls mail(), but this only sets the "From:" and not the "Return-path:"
I agree that the message-id is not that important, but it would be nice if one could have the "Return-path:" reflect the same domain as "From:"

I have this in php.ini (the -r parameter is supposed to set the return-path, but seems to have no effect):

sendmail_path = "sendmail -t -i -f ***@mydomain.com -r ***@mydomain.com"

and in the php code sending the mail, the headers are also set:

$headers = 'From: me < ***@mydomain.com >' . PHP_EOL .
'Reply-To: me < ***@mydomain.com >' . PHP_EOL .
'X-Mailer: www.mydomain.com' ;
...
$result = mail($to, $subject, $message, $headers);

The outgoing mail does have the correct "From:" and "Reply-To:" headers, but the "Return-Path" stays as the hostname of the machine --
...
Wietse Venema
14 years ago
Permalink
Post by R.A. Imhoff
I have this in php.ini (the -r parameter is supposed to set the
If PHP's sendmail_path ignores the ``sendmail -f ***@senderdomain''
option, then you need to ask for support on the PHP mailing list.

The -f command-line option is supported by pretty much any UNIX
MTA, not just Postfix or Sendmail.

Please report back what the solution is - there are lots of broken
websites that send mail with an invalid envelope sender address
such as www-***@hostname, and it would be nice to have the solution
on file here.

Wietse
Wietse Venema
14 years ago
Permalink
Post by R.A. Imhoff
Thank you for your suggestions!
I did set the "From: " correctly, both in the php.ini and in the
php code that calls mail(), but this only sets the "From:" and
not the "Return-path:" I agree that the message-id is not that
important, but it would be nice if one could have the "Return-path:"
reflect the same domain as "From:"
I have this in php.ini (the -r parameter is supposed to set the
According to PHP documentation, extra sendmail arguments must be
supplied with the FIFTH mail() argument.

http://us.php.net/manual/en/function.mail.php says:

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

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.

So there is the answer, for posteriority.

Wietse
mouss
14 years ago
Permalink
...
R.A. Imhoff
14 years ago
Permalink
In fact what finally does set the Return-path is to use the "-r" parameter in the 5th place:

$result = mail($to, $subject, $message, $headers, "-r ***@example.com")

the "-f" sets the "From:", but that was already working by setting it in the $headers or in the php.ini

What's odd is that putting the -r parameter should also work from the php.ini settings but doesn't.

Thank you all!
...
Wietse Venema
14 years ago
Permalink
Post by R.A. Imhoff
the "-f" sets the "From:", but that was already working by setting it in the $headers or in the php.ini
No, that is incorrect.

With POSTFIX, the -f and -r options do exactly the same thing:

case 'f':
sender = optarg;
break;
...
case 'r': /* obsoleted by -f */
sender = optarg;
break;

If you look in your logging, you may find that you are handing the
mail to something other than POSTFIX.

POSTFIX submissions looks like:

pickup[xx]: yyy: uid=1001 from=<wietse>
cleanup[zz] yyy: message-id=<***@spike.porcupine.org>

Wietse
R.A. Imhoff
14 years ago
Permalink
This is interesting: in testing this on the server in question, the "-f" does nothing (with a lowercase -f).

In an older sendmail man page I just came across it says "... -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."
So I guess my php code doesn't get permission to use it. (The current man page doesn't have that ...)

"-r" sets the Return-Path and the From if there is no From in the $headers set in the php code, otherwise the -r sets only the Return-Path.


So what works for my setup is:

$headers = 'Reply-To: ri <reply-***@mydomain.net >' . PHP_EOL . 'From: ri <from-***@mydomain.net >' ;
$subject ="some subject";
$message = 'some text';
$to = "some one <***@some.com>";

$done = mail($to, $subject, $message, $headers, '-r return-***@mydomain.net');


The message then arrives with the different addresses as expected:

Return-Path: <return-***@mydomain.net>
To: some one <***@some.com>
Subject: some subject
Post by Wietse Venema
Post by R.A. Imhoff
the "-f" sets the "From:", but that was already working by setting it in the $headers or in the php.ini
No, that is incorrect.
sender = optarg;
break;
...
case 'r': /* obsoleted by -f */
sender = optarg;
break;
If you look in your logging, you may find that you are handing the
mail to something other than POSTFIX.
pickup[xx]: yyy: uid=1001 from=<wietse>
Wietse
Wietse Venema
14 years ago
Permalink
Post by R.A. Imhoff
This is interesting: in testing this on the server in question,
the "-f" does nothing (with a lowercase -f).
In an older sendmail man page I just came across it says "... -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."
POSTFIX does not limit the use of the -f option.

As shown before, the code for -f is identical, line by line,
to the code for -r'

case 'f':
sender = optarg;
break;
...
case 'r': /* obsoleted by -f */
sender = optarg;
break;

Please stop spreading false rumors or else provide actual evidence
that the two options produce different results with POSTFIX.

There is already enough bad information on the Internet, please do
not drag down this mailing list too with inaccurate and unsupported
claims.

Wietse

Continue reading on narkive:
Loading...