Whenever the form is submitted, no email is sent and all I get is the “Error” so I guess the
<?php if(!isset($hasError)) ?>
is the only thing being run
<?php
/*
Template Name: Bobs Contact Form
*/
?>
<?php get_header(); ?>
<div class="map">
<iframe width="480" height="494" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Napolitano+Realty,+939+Orange+Avenue,+Coronado,+CA+92118-2609&aq=2&sll=37.0625,-95.677068&sspn=40.409448,93.076172&ie=UTF8&hq=Napolitano+Realty,&hnear=939+Orange+Ave,+Coronado,+San+Diego,+California+92118&ll=32.686543,-117.179229&spn=0.006295,0.006295&output=embed"></iframe>
</div>
<?php
//If the form is submitted
if(isset($_POST['submitted']))
{
//Check to make sure that the name field is not empty
if(!isset($_POST['contactName'])) {
$nameError = 'You forgot to enter your name.';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
//Check to make sure sure that a valid email address is submitted
$email = $_POST['email'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailError = 'You entered an invalid email address.';
$hasError = true;
}
//Check to make sure comments were entered
if(!isset($_POST['comments']))
{
$commentError = 'You forgot to enter your comments.';
$hasError = true;
} else {
$comments = trim($_POST['comments']);
}
//If there is no error, send the email
if(!isset($hasError)) {
echo 'email sent';
$phone = $_POST['phone'];
$to= 'example@example.com';
$subject = 'Contact Form Submission from '.$name;
$body = 'Name: '.$name." \
\
".'Email: '.$email." \
\
".'Phone: '.$phone." \
\
".'Comments: '.$comments;
$headers = 'From: My Site <'.$to.'>' . "\\r\
" . 'Reply-To: ' . $email;
$emailSent = mail($to, $subject, $body, $headers);
} else {
echo 'Error';
}
if($emailSent) {
?>
<div class="thanks">
<h1 style="text-transform: none;">Thanks, <?=$name;?></h1>
<p>Your email was successfully sent. I will be in touch soon.</p>
</div>
<?php }
} else { ?>
<div class="contact-form" style="padding:25px; float:left; margin-top: 50px; background-color: rgba(195,166,96,.13); height: 444px; width: 400px;">
<h1 style="text-align:center; margin-left: -25px; margin-top: -25px; width: 420px; color: white; font: 700 30px/1.1 georgia,'times new roman','sans-serif'; text-transform: uppercase;">Contact Form</h1>
<form action="<?php the_permalink(); ?>" id="contactForm" method="post">
<ol class="forms" style="margin-top:25px; width:400px; clear:none; margin-left:0">
<li><label for="contactName">Name</label>
<input type="text" name="contactName" id="contactName" class="requiredField" />
<?php if($nameError != '') { ?>
<span class="error"><?php echo $nameError; ?></span>
<?php } ?>
</li>
<li><label for="email">Email</label>
<input type="text" name="email" id="email" class="requiredField email" />
<?php if($emailError != '') { ?>
<span class="error"><?php echo $emailError; ?></span>
<?php } ?>
</li>
<li><label for="phone">Phone</label>
<input type="text" name="phone" id="phone" />
</li>
<li class="textarea"><label for="commentsText">Comments</label>
<textarea name="comments" id="commentsText" rows="10" cols="30" class="requiredField" style="height:150px"></textarea>
<?php if($commentError != '') { ?>
<span class="error"><?php echo $commentError; ?></span>
<?php } ?>
</li>
<li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" style="float: right; padding-top: 9px; padding-bottom: 8px; padding-left: 6px; padding-right: 6px; font-family: georgia, 'times new roman',sans-serif;
background-color: #F47D3B; color: white; text-transform:uppercase">Submit</button></li>
</ol>
</form>
</div>
<?php
}
?>
<?php get_footer(); ?>
is the only thing being run…
Why?
the script is at http://crowntownbob.com/contact/
Thanks…