Basic mail function (PHP) additional “-f” parameter question

核能气质少年 提交于 2020-01-23 07:46:43

问题


Is the -f additional parameter correctly set in this mail function.

@mail("example@exmaple.com.uy",$title,$body,$headers,"-f");

I am Getting the X Warning from some servers.

Sorry for the basic question but some parts of the documentation got me confused (specially some user comments).

Thanks in advance!


回答1:


From the manual:

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.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.

source: http://www.astahost.com/info.php/Sending-Mail-Php39s-Mail-Function_t2728.html

The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using 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. You may need to add the user that your web server runs as to your sendmail configuration to prevent a 'X-Warning' header from being added to the message when you set the envelope sender using this method. Example 3. Sending mail with extra headers and setting an additional command line parameter.

i.e:

<?php
mail("nobody@example.com", "the subject", $message,
"From: webmaster@{$_SERVER['SERVER_NAME']}", "-fwebmaster@{$_SERVER['SERVER_NAME']}");
?>

After -f you need to set the outgoing email address to prevent the warning (in this case its webmaster@-the domain-




回答2:


If your machine runs on a linux server. Your apache install more than likely runs under the user 'www-data'.

you can figure this out easily by going to /etc/apache2 and typing

cat envvars | grep APACHE_RUN_USER

whatever is after '=' is what user apache is running as.

You need to add this user to the trusted-users file. This file is located at /etc/mail/trusted-users

just

nano /etc/mail/trusted-users

and write 'www-data'.

save and you should be good to go.




回答3:


-f should be followed by the address you want as envelope address on your mail.

@mail("example@exmaple.com.uy",$title,$body,$headers,"-fexample@exmaple.com.uy");



回答4:


Have you tried sending it without the -f flag?

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.




回答5:


You need to specify an email address after the -f flag. Like this: "-fexample@example.com". You may also need to add the user that your web server run as to your sendmail configuration.



来源:https://stackoverflow.com/questions/4205228/basic-mail-function-php-additional-f-parameter-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!