The code below works to some degree. But has a few problems. Each time I fill it out and sends an email, it doesn’t send a new email, it just keeps on adding to the last email it sent me. I want the form to send a brand new email each time it is filled out.
Also I need help with the verification code. The verification code is: “Is fire hot or cold?”
And the last thing is, I need help with setting up the error strings for each field according to what they are.
<?php
if(isset($_POST['Submit'])){ //check if user submitted the contact form
$error="";
if($_POST['contact_name']=='')$error.="Name required.<br/>";
if($_POST['contact_business']=='')$error.="Website required.<br/>";
if($_POST['contact_email']=='')$error.="Email required.<br/>";
if($_POST['contact_phone']=='')$error.="Phone required.<br/>";
if($_POST['contact_comment']=='')$error.="Comment required.<br/>";
if($error!=""){
//if any errors skip mailing and display the errors for users.
echo "<span style='color:red'>$error</span>";
}else{
// get admin email from wordpress default options
$to=get_option('admin_email');
$subject="Photography Request: ".$_POST['contact_reason'];
$body="
Hi ";
$body.="
You have an inquiry:";
$body.="
Regarding: ".$_POST['contact_reason'];
$body.="
Name: ".$_POST['contact_name'];
$body.="
Website: ".$_POST['contact_business'];
$body.="
Email: ".$_POST['contact_email'];
$body.="
Phone: ".$_POST['contact_phone'];
$body.="
Comment:
".$_POST['contact_comment'];
// wordpress default handy mail function
wp_mail( $to, $subject, $body);
echo "<span style='color:green;'>your comment sent to admin successfully</span>";
// display success message.
}
}
?>
I know most of you guys are very busy so I don’t need a response ASAP. Just answer when you guys have some free time. Thanks for all your help.