Thank you postfix--- and Ralph for showing me options for working around the 
defect.  But these workarounds are not ideal because they require the user to 
manually look up the display name and it requires a lot of extra typing both on 
the command line and when writing PHP scripts.  If you have multiple calls to 
mail() it is easy to miss one and it seems like this is something people will 
continue to struggle with until it is fixed.

It is never correct to use one user's name but a different user's email address 
in the headers.  There is no need to "guess" what is the correct name.  It is 
right there in /etc/passwd.  The original sendmail handles this correctly both 
with and without the -f option.  The postfix version fails when using the -f 
option (but works correctly without it).

On 12/23/2025 11:34 PM, postfix--- via Postfix-users wrote:
>> The sendmail command (ie. /usr/sbin/sendmail) normally extracts the sender's 
>> display name
>> from the comment field of /etc/passwd. This is used to populate the "From" 
>> header. However,
>> when the -f option is used the /etc/passwd file is not consulted and the 
>> display name is
>> instead set to the account name of the current user. This is both incorrect 
>> and confusing
>> to the recipient since the display name does not match the sender's account 
>> name.
>
>
> You can specify the sender's address in sendmail, if you do not then sendmail 
> will populate it with something. That is what is happening, sendmail is 
> guessing and populating the value because you didn't.
>
> To solve the problem, tell sendmail what you want the address to be. You send 
> the headers before the message body separated by an empty line in the "data 
> section". Same as when manually sending the email during the SMTP data 
> command.
>
>
>
> BY COMMAND LINE:
>
>   sendmail -f [email protected] [email protected] << 'EOF'
>   From: "Pretty Name" <[email protected]>
>   To: [email protected]
>   Subject: Example subject
>
>   This is the message body.
>   EOF
>
>
>
> BY COMMAND LINE WITH FILE:
>
>   /path/email_data.txt
>     From: "Pretty Name" <[email protected]>
>     To: [email protected]
>     Subject: Example subject
>
>     This is the message body.
>
>   sendmail -f [email protected] [email protected] < 
> /path/email_data.txt
>
>
>
> USING PHP:
>
>   <?PHP
>     ...
>     $cmdLineParams = "-f $from";
>     $headers = ['From' => $from];
>     $body  = "This is the message body.\n";
>     mail($to, $subject, $body, $headers, $cmdLineParams);
>   ?>
>
>
> _______________________________________________
> Postfix-users mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
_______________________________________________
Postfix-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to