【问题标题】: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\""
    

    【讨论】:

      【解决方案2】:

      基于 PHP 源,error_log 函数调用 php_mail 并为此参数发送 NULL 值。

          case 1:     /*send an email */
              if (!php_mail(opt, "PHP error_log message", message, headers, NULL)) {
                  return FAILURE;
              }
              break;
      

      (来源:php-src/ext/standard/basic_functions.c

      您必须坚持使用set_error_handler 并编写自己的错误处理程序。

      【讨论】:

        【解决方案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);
        

        【讨论】:

          【解决方案4】:

          你需要使用error_log_handler,见http://php.net/manual/en/function.set-error-handler.php

          mixed set_error_handler ( callable $error_handler [, int $error_types = E_ALL | E_STRICT ] )
          

          设置一个函数来处理脚本中的错误。我相信这是向 error_logs 添加函数的标准方法。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-09-27
            • 1970-01-01
            • 1970-01-01
            • 2021-01-18
            相关资源
            最近更新 更多