Hey,
I'm using a very simple code to let people post messages to a .dat file. This works fine. Now I want to receive a HTML-mail whenever a message is posted, but I doesn't work properly. Is there anyone who can spot the error in the code below?
Thanks in advance, Michiel
PHP Code:
function sendMail()
{
/* Recipients */
$to = "My name <my@domain.com>";
/* Message */
$body = '
<BODY bgcolor="#eeeeee" topmargin="5" leftmargin="5" marginwidth="0" marginheight="0" link="#3f3f3f">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD bgcolor="#000033">
<TABLE border="0" cellpadding="0" cellspacing="1" width="100%">
<TR valign="top">
<TD>
<FONT face="arial" size="2" color="orange"><B> New Message:
</TD>
</TR>
<TR>
<TD bgcolor="#eeeeee">
<TABLE border="0" cellpadding="3" cellspacing="0" width="100%">
<TR>
<TD>
<FONT face="arial" color="#000033" size="2"><B>'.
$name .'has posted a new message in'. $category.' </B><BR><BR>
<I>Message:</I><BR><BR>'.
$message.'
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
';
/* Content-type header */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Me\r\n";
/* SEND MAIL!! */
mail($to, $subject, $body, $headers);
}
If($name !== "")
{
$fp = fopen($path, "r");
$oldmessages = fread($fp,filesize($path));
fclose($fp);
$date = date("d-m-Y (H:i:s)");
$message = ereg_replace("\n","<BR>",$message);
$message = ereg_replace('\\\"',""",$message);
$message = ereg_replace('\\\'',""",$message);
$fp = fopen($path, "w");
fwrite($fp,$name."\n");
fwrite($fp,$subject."\n");
fwrite($fp,$message."\n");
fwrite($fp,$date."\n");
fwrite($fp,$oldmessages);
fclose($fp);
// Send Email
//sendMail();
// Confirmation
echo "$name, your message is succesfully posted!";