Hi there folks,
I was just wondering if anybody could help me with a problem I'm having with a contact form not working?
Its a basic php form, I eventually want to integrate it into my contacts page but just for now I'm using two php pages, one for the form and a confirmation page. I have added a destination email address - have obviously omitted in this paste and I have enabled scripting on my domain.
Code:
Contact.php
<!-------INSERT THIS CODE WHERE YOU WOULD LIKE YOUR FORM TO BE------>
<?php>
$A= rand(1, 9);
$B= rand(1, 9);
$C=$A+$B;
?>
<form method="post" action="contactus.php" >
<table width="400" border="0" align="left">
<tr><td>Name:</td><td><input type="text" name="Name" size="20" maxlength="20"></td></tr>
<tr><td>E-Mail:</td><td><input type="text" name="Email" size="20" maxlength="35"></td></tr>
<tr><td>Phone:</td><td><input type="text" name="Phone" size="14" maxlength="14"></td></tr>
<tr><td>Question:</td><td><textarea cols="40" rows="5" maxleanth="255" name="Comment"></textarea></td></tr>
<tr><td><h3><?php echo $A."+".$B."="; ?></td><td>Please answer to validate your email.<input type="text" name="Yanswer" size="3" maxlength="3"></td></tr>
<tr><td height="25"></td></tr>
<input type="hidden" name="Answer" value="<?php echo "$C"; ?>">
<tr><td></td><td><input type="submit" value="CONTACT US"></td></tr>
<tr><td height="100"></td></tr>
</table>
</form>
<!------------------------------------------------------------------>
Contactus.php
<!------INSERT THIS CODE IN YOUR THANK YOU PAGE. IT SHOULD BE NAMED contactus.php-------->
<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Phone=$_POST['Phone'];
$Comment = $_POST['Comment'];
//EDIT THE FOLLOWING LINE , INSERT THE SITE EMAIL
$To="myemailaddress.com";
$Subject="Contact form, Your Website";
$Answer=$_POST['Answer'];
$Yanswer=$_POST['Yanswer'];
$Message="
From: $Name
Phone: $Phone
Email: $Email
$Comment";
if ($Answer==$Yanswer){
mail($To,$Subject,$Message);
echo "<h3>Your message has been sent. Thank you.<table><tr><td height=\"1375\"></td></tr></table>";}
else{
echo "<h3>You did not enter the correct answer to the validation question. Please click back and try again.<table><tr><td height=\"1375\"></td></tr></table>";
}
?>
<!-------------------------------------------------------------------------------------->
Kind Regards,
Sukhjinder Singh