Hi there,
Ive posted this earlier on and i actually managed to get a semi-solution to the problem. I am trying to create a script that sends and email and also logs each email sent as an xml document.
I managed to get it work first time around however once u submit the second email (i.e the second record) i get an error saying "XML document must have a top level element. Error processing resource".
Can anyone help me solve this problem please ?
Heres the code :
<?php
if (!(getenv("HTTP_X_FORWARDED_FOR"))) {
$ip= getenv("REMOTE_ADDR");
} else {
$proxy_address= getenv("REMOTE_ADDR");
$ip= getenv(HTTP_X_FORWARDED_FOR);
}
$host = gethostbyaddr (getenv("REMOTE_ADDR"));
$ip= getenv("REMOTE_ADDR");
$dt= date("D F j, Y, g:i:s a");
$to= "email@harry.demon.nl";
$headers .= "From: $host <someone@someone.com>\n";
$headers .= "X-Sender: $host <halasad@blanketware.com>\n";
$headers .= "X-Mailer: PHP ". phpversion() ."\n";
$headers .= "X-Priority: 1\n";
$subject = "Error Notification from $ip";
$body = "Error generated at $ip on $dt.";
mail( $to, $subject, $body, $headers );
$xml_string =
"<report>
<host>$host</host>
<ipaddress>$ip</ipaddress>
<errmsg>$subject</errmsg>
<date>$dt</date>
</report>
";
$pagename = "errorlog.xml";
$newlog = $xml_string;
$size = file_exists( $pagename ) ? filesize( $pagename ) : 0;
$fp = fopen( $pagename, 'a+' );
if( $size > 0 ) {
fseek( $fp, 0 );
$log = fread( $fp, $size );
if( preg_match( '|<errorlog>(.*)</errorlog>|s', $log, $match )) {
$newlog = $match[1] . $newlog;
}
ftruncate( $fp, 0 );
}
$newlog = "<?xml version='1.0'?><errorlog>$newlog</errorlog>";
fwrite($fp, $newlog );
fclose($fp);
?>
Thanks,
Hussam