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

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

Posted by: admin July 12, 2020 Leave a comment


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?

How to&Answers:
error_log("Error message", 1, "[email protected]", "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.


Thank you niet-the-dark-absol!

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


    $headers = "From: SOME ROBOT <[email protected]>\r\n" .
               "Reply-to: SOME HUMAN <[email protected]>";
               "Subject: My custom subject on including date of: " . $dateTime . "\r\n" .
    $emailto = "[email protected]";
    $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)

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