error_log将参数传递给发件人

Zde*_*hek 5 php email debugging error-handling

当我使用函数error_log与$message_type = 1- 通过电子邮件发送时,我需要传递给sendmail额外的参数"-f" . $sendermail

有没有办法可以将参数传递给发件人,同样可以用邮件和$additional_parameters?

文档说

此消息类型使用与mail()相同的内部函数.

但我看不清楚如何做到这一点.

Leo*_*lis 2

就“快速”方法而言,假设您的意思是传递额外的参数等,那么就不行。查看 的源代码error_log,注意它NULL被显式传递给该mail函数的相关参数:

if (!php_mail(opt, "PHP error_log message", message, headers, NULL)) {
Run Code Online (Sandbox Code Playgroud)

除了像set_error_handler其他人提到的那样使用之外,您可以尝试使用运行时配置mail.force_extra_parameters(请参阅文档)。

强制添加指定参数作为额外参数传递到 sendmail 二进制文件。即使在安全模式下,这些参数也始终会替换 mail() 的第五个参数的值。

我以前使用过这个,但需要注意的是它会覆盖其他选项,因此您可能必须考虑它是否对您有益。例如,这是我.conf在 apache 开发服务器上的 include 中使用的内容:

# force envelope sender and name and in turn ignore any passed in to PHP mail() function
php_admin_value mail.force_extra_parameters "-f leonard@mydevserver.co.uk -F \"Development: leonard\""
Run Code Online (Sandbox Code Playgroud)