please find below my PHP code for a contact form. I'm a newby in PHP and have the following problem with the code:
Visitors of my website can fill in their name, e-mail, subject and message. When they send the message I receive it in my hotmail but for some reason the senders name and the subject are not mentioned (unknown). Resulting in Hotmail considering the mail as a threat. I have to "unlock" the mail before I can read it. Very anoying but I don't know what's wrong with the PHP code. please help!
the code:
Code: Select all
<?
if(!empty($_POST['Submit']))
{
if(strlen($_POST['name']) == 0)
{ $error_msg =" U heeft uw naam niet ingevuld / your name was not entered<br>"; }
if(!ereg("^[_a-zA-Z0-9-]+(\.[*@([a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$", $_POST['uwemail']))
{ $error_msg .=" Het ingevoerde mailadres lijkt niet correct / entered mailaddress not valid<br>"; }
if(strlen($_POST['field']) ==0)
{ $error_msg .=" U heeft geen bericht ingevoerd / no message entered<br>"; }
if(!empty($error_msg))
{
echo "<b>Bericht niet verzonden om volgende reden... / Mail did not go trough because....</b><br><br>";
echo $error_msg;
echo "<br>Klik hier om opnieuw in te voeren / click to re-enter <a href=java script:history.back(1)>terug / return</a> <br><br>";
}
else
{
$recipient = "info@ali.nl";
$subject = $sub;
$header = "From: " . $uwemail . "\n";
$mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n";
$mail_body .= "De volgende persoon vulde het contact formulier in:\n\n";
$mail_body .= "Naam: " . $_POST['name'] . "\n";
$mail_body .= "E-mailadres: " . $_POST['uwemail'] . "\n\n";
$mail_body .= "Bericht:\n";
$mail_body .= $_POST['field'];
$mail_body .= "\n\n -- Einde van het contact bericht --";
mail($recipient, $subject, $mail_body, $header);
echo "<b>Bedankt voor uw inzending / thank you for submitting your message</b>";
}
}
else
{
?><body bgcolor="#2C172F">
<form action="contact/contact.php" method="POST" name="contact">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><br>
<table width="73%" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1" colspan="2"><div align="center">
<p><font size="5"><strong><font color="#FFFFCC">CONTACT ALIDUS FIJNPROEVERIJ</font></strong></font></p>
<p> </p>
</div></td>
</tr>
<tr>
<td height="1"><p><font color="#FFFFFF" size="4">Naam / Name</font></p>
<p> </p></td>
<td width="423" height="2"> <p>
<input type="text" name="name" size="40">
</p>
<p> </p></td>
</tr>
<tr>
<td height="1"><p><font color="#FFFFFF" size="4">E-mail </font></p>
<p> </p>
<p> </p></td>
<td height="2"> <p>
<input type="text" name="uwemail" size="40">
</p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td width="205" class="Kleiner"><p><font color="#FFFFFF" size="4"> Onderwerp / Subject</font></p>
<p> </p></td>
<td><p>
<input type="text" name="sub" size="40">
</p>
<p> </p></td>
</tr>
<tr>
<td width="205" height="100" class="Kleiner"><p><font color="#FFFFFF" size="4">Bericht / Message</font></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</td>
<td> <p>
<textarea name="field" wrap="VIRTUAL" cols="55" rows="10"></textarea>
</p>
</td>
</tr>
<tr>
<td width="205" height="62"> </td>
<td> <div align="left">
<p>
<input type="Submit" name="Submit" value="Verzenden / Submit">
</p>
<p> </p>
</div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="90%">
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<?php
}
?>