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:[email protected]; 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

1

2 Answers 2

0

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

try this..

$email_header = 'Content-type: text/html; charset=iso-8859-1;'
$email_header .= 'From:[email protected]; Content-type: text/html; charset=iso-8859-1;';

you were not concating the $email_header string..

Sign up to request clarification or add additional context in comments.

4 Comments

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:[email protected]; Content-type: text/html; charset=iso-8859-1;';
ohh ok. no problem.. try putting ob_clean() or ob_flush() function before declaring your $email variable...
Sadly didnt work my friend. Thanks anyway for trying. Any other ideas?
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); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.