【问题标题】:error_log passing parameter to sendererror_log 将参数传递给发件人
【发布时间】:2016-05-24 08:24:37
【问题描述】:
当我使用函数error_log 和$message_type = 1 - 通过电子邮件发送时,我需要传递给sendmail 额外参数"-f" . $sendermail
有什么方法可以将参数传递给发件人,就像使用mail 和$additional_parameters 一样?
文档说
此消息类型使用与 mail() 相同的内部函数。
但我看不到快速的方法。
【问题讨论】:
标签:
php
email
debugging
error-handling
【解决方案1】:
就执行此操作的“快速”方式而言,假设您的意思是传递额外的参数等,那么不会。查看source code for error_log,注意到NULL 被显式传递给mail 函数的相关参数:
if (!php_mail(opt, "PHP error_log message", message, headers, NULL)) {
除了其他人提到的使用set_error_handler,您可以尝试使用运行时配置mail.force_extra_parameters (see docs)。
强制添加指定参数作为额外参数传递给 sendmail 二进制文件。这些参数将始终替换 mail() 的第 5 个参数的值,即使在安全模式下也是如此。
我以前使用过它,但需要注意的是它会覆盖其他地方的选项,因此您可能需要考虑它是否对您有益。例如,这是我在我的 apache 开发服务器上的 .conf 包含中使用的:
# 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\""
【解决方案3】:
我没有尝试使用 message_type 1 的 error_log,但我知道 mail 的工作原理,所以我想你必须尝试类似的方法:
$headers = "From: $name <{$email}>\r\n".
"Reply-To: {$email}\r\n";
error_log('Foo', 1, 'bar@php.com', $headers);