How do I change the subject of my php error email?

2019-04-26 08:55发布

问题:

I have the following:

      error_log("big error!!", 1, my email address);

When the message is delivered it says "PHP error_log message" in the subject line.

Can someone show me how to customize the message subject?

回答1:

error_log("Error message", 1, "me@example.com", "Subject: My custom subject");

The fourth parameter of error_log allows you to specify custom headers, of which Subject is the subject of the email.



回答2:

Thank you niet-the-dark-absol!

I was able to generate this off of your recommendations on separating the headers.

<?php

    $dateTime=date("Y_m_d_H_i_s");
    $headers = "From: SOME ROBOT <somerobotyouusedtoknow@somecompany.com>\r\n" .
               "Reply-to: SOME HUMAN <somehumanyoudoknow@somecompany.com>";
               "Subject: My custom subject on including date of: " . $dateTime . "\r\n" .
    $emailto = "JayRizzo@somecompany.com";
    $emailbody = "This is the body of the email: Error message";

error_log($emailbody, 1, $emailto, $headers);

?>

I got a proper response and was able to change more than just the Subject or Reply-to or From address.

I'm posting this only because all I find is that you cannot change more than one header at a time, and this proves that wrong. (unless it is just an improvement of the PHP version that I'm using)

NOTE: My version of PHP:

~: php -v

PHP 7.2.0RC6 (cli) (built: Nov 12 2017 08:50:58) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies