1

quicky question. I have set a custom error handler for an application I am making that writes to an error log and will also generate an html email to the main administrator using the code below.

function log_to_errors($number, $message, $file, $line, $vars){

if(ENVIRONMENT !== 'development'):
    ini_set('log_errors', 1);
    ini_set('error_log', '../error_logs.txt');

    $email = "
        <div style='background: rgb(224, 224, 224); padding: 5px 10px;'>
            <p>An error reference of ".$number." has occured on line: ".$line." in: <strong>".$file."</strong></p>
            <p>".$message."</p>
            <pre>".print_r($vars, 1)."</pre>
        </div>
    ";

    $email_header = 'Content-type: text/html; charset=iso-8859-1;';
    error_log($email, 1, ADMIN_EMAIL, $email_header); 
endif;
}

set_error_handler('log_to_errors');

I would like to amend this line:

$email_header = 'Content-type: text/html; charset=iso-8859-1;'

so that I can set custom information for the other email credentials ie the 'from and subject' elements of the email but when I try and do something like this:

$email_header = 'From:errors@example.com; Content-type: text/html; charset=iso-8859-1;';

it breaks the html in the email. Can someone point me in the right direction so I can set a message subject etc for the email.

Many thanks, Lewis

2 Answers2

0

you are missing a dot (.) before $email_header ..

try this..

$email_header = 'Content-type: text/html; charset=iso-8859-1;'
$email_header .= 'From:errors@example.com; Content-type: text/html; charset=iso-8859-1;';

you were not concating the $email_header string..

Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32
  • Apologies for the lack of clarity, I'm not trying to concatenate here. I was just illustrating what it was that I was trying to do. I only have the following line: $email_header = 'From:errors@example.com; Content-type: text/html; charset=iso-8859-1;'; – lcainswebdeveloper Mar 05 '14 at 15:56
  • ohh ok. no problem.. try putting `ob_clean()` or `ob_flush()` function before declaring your `$email` variable... – Nishant Solanki Mar 05 '14 at 16:29
  • Sadly didnt work my friend. Thanks anyway for trying. Any other ideas? – lcainswebdeveloper Mar 05 '14 at 17:08
  • may be this could help you.. http://stackoverflow.com/questions/3058897/sending-html-email-from-php... http://stackoverflow.com/questions/18738685/php-send-mail-with-html-not-working – Nishant Solanki Mar 05 '14 at 17:35
0
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . chr(13) . chr(10);
    $headers .= 'Content-type: text/html; charset=utf-8' . chr(13) . chr(10);
    $headers .= 'Content-Transfer-Encoding: 8bit' . chr(13) . chr(10);

    // Additional headers
    $headers .= 'To: '. $to . chr(13) . chr(10);
    $headers .= 'From: '. $from . chr(13) . chr(10); 
    $headers .= 'Reply-To: '. $clientmail . chr(13) . chr(10) . chr(13) . chr(10); 
vatavale
  • 1,470
  • 22
  • 31