I bought a WP theme a few months ago and it works great! I am trying to edit the contact.php / sendmail.php
I have successfully added in a field, it shows up in the body of the email and sends correctly. However, I am have a lot of trouble getting the new field "school(s) of interest" to highlight properly (with hidden text) when the field hasn't been filled. The contact form in question can be found here: http://www.northbrookmontessori.org/school-tours/
sendmail.php
<?php
//validate fields
$errors = '';
//has the form's submit button been pressed?
if( !empty( $_POST['myformsubmit'] ) )
{
// HAS THE SPAM TRAP FIELD BEEN FILLED IN?
if( !empty( $_POST['favouriteColour'] ) )
{
exit;
}
$myemail = $_POST['youremail'];
$thankyou = $_POST['thankyou'];
$formerror = $_POST['formerror'];
if(empty($_POST['name']) ||
empty($_POST['school']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$school = $_POST['school'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } //send email
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission from $name";
$email_body = "$name has sent you this email through the contact form: \n \n".
"Name: $name \n".
"School(s) of interest: $school \n".
"Email: $email_address \nMessage: \n\n$message";
$headers = "From: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: ' . $thankyou);
}
else {
header('Location: ' . $formerror);
}
}
?>
contact.php
<!-- ***** CONTACT -->
<div class="block_wrapper <?php if($bb_animation == 'yes'){ echo 'animation' . $anim1_number; ?> animated <?php } ?><?php echo ' '.$custom_width; ?>">
<div class="box_full<?php if($margin_top != ''){echo ' ' . $margin_top;} ?><?php if($margin_bottom != ''){echo ' ' . $margin_bottom;} ?><?php if($custom_classes != NULL){echo ' ' . $custom_classes;} ?>">
<form id="theform" class="form mt35" method="post" action="<?php echo get_template_directory_uri(); ?>/sendmail.php">
<p class="hRow">
<label for="favouriteColour">Favourite colour (do not fill in)</label>
<span><input type="text" name="favouriteColour" id="favouriteColour" value="" /></span>
</p>
<input type="hidden" name="youremail" id="youremail" value="<?php if(!empty($contact_email)){echo $contact_email;} ?>" />
<input type="hidden" name="thankyou" id="thankyou" value="<?php if(!empty($contact_thankyou)){echo $contact_thankyou;} ?>" />
<input type="hidden" name="formerror" id="formerror" value="<?php if(!empty($contact_error)){echo $contact_error;} ?>" />
<p class="name validated">
<label for="name">Name</label>
<span><input type="text" name="name" id="name" /></span>
</p>
<p class="school validated">
<label for="school">School(s) of interest</label>
<span><input type="text" name="school" id="school" /></span>
</p>
<p class="email validated">
<label for="email">E-mail</label>
<span><input type="text" name="email" id="email" /></span>
</p>
<p class="text validated">
<label for="message">Message</label>
<textarea name="message" id="message" rows="50" cols="100"></textarea>
</p>
<p class="submit">
<input type="submit" class="buttonmedium float_r" name="myformsubmit" value="Send Email" />
</p>
<p id="error">* There were errors on the form, please re-check the fields.</p>
</form>
</div>
<div class="clear"></div>
</div><!-- ***** END CONTACT -->
you need to go to the file:
http://www.northbrookmontessori.org/wp-content/themes/modular/js/settings.js?ver=4.2.2
and edit the top where it says:
// Place ID's of all required fields here.
add in school
Related
I am trying to create a pseudo captcha to stop spambots spamming my contact form. I have php so that it doens't allow the user to send if the form isn't filled out and instead gives a message. I'm trying to make it so that it doesn't send if the "I am a robot" checkbox is checked as well. Since bots tend to check all checkboxes, I figured this may work. I am pretty new to PHP so go easy on me.
I tried using !empty($robots) which didn't work. I also tried !isset($robots) I messed with a second IF statement.
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$client_message = $_POST['client_message'];
$to = "rtisticpictures#gmail.com";
$subject = "Client Message";
$cmessage = $_POST['client_message'];
$message = $first_name . " " . $last_name . "\n\n Phone:" . $phone . "\n\n email:" . $email . "\n\n" . $cmessage;
if(empty($first_name) || empty($last_name) || empty($phone) || empty($cmessage) || empty($email))
{
echo "Your message can not be sent without all fields filled in, or you have checked that you are a robot. We do not allow bots to send email.";
; // Note this
}
else
{
mail ($to, $subject, $message, "From: " . $first_name . $last_name);
echo "Your message has been Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
HTML FORM
<form action="contact_form.php" method="post" name="contact_form">
<p>First Name: <input name="first_name" type="text" />
Last Name: <input name="last_name" type="text" />
Phone Number: <input name="phone" type="text" placeholder="(999)999-9999" />
E-mail:<input name="email" type="text" placeholder="your#email.com" />
</p>
<p>
<textarea name="client_message" cols="5" rows="3" placeholder="Write your message here."></textarea>
</p>
<div class="6u 12u(2)">
<input type="checkbox" id="human" name="human" unchecked="">
<label for="human">I am not a robot.</label></div>
<div class="6u 12u(2)">
<input type="checkbox" id="robots" name="robots" unchecked="">
<label for="robots">I am a robot.</label>
</div>
<p>
<input type="submit" name="submit" id="submit" value="Send"/>
<input type="reset" name="reset" id="reset" value="Clear"/>
</p>
</form>
I would like it to send only when the 'human' checkbox is selected and the 'robots' checkbox is not selected.
If you want to check if checkbox is checked in PHP you should use isset, in your case:
if(empty($first_name) || empty($last_name) || empty($phone) || empty($cmessage) || empty($email) || !isset($_POST['robots']))
And full code:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$client_message = $_POST['client_message'];
$to = "rtisticpictures#gmail.com";
$subject = "Client Message";
$cmessage = $_POST['client_message'];
$message = $first_name . " " . $last_name . "\n\n Phone:" . $phone . "\n\n email:" . $email . "\n\n" . $cmessage;
if(empty($first_name) || empty($last_name) || empty($phone) || empty($cmessage) || empty($email) || !isset($_POST['robots']))
{
echo "Your message can not be sent without all fields filled in, or you have checked that you are a robot. We do not allow bots to send email.";
; // Note this
}
else
{
mail ($to, $subject, $message, "From: " . $first_name . $last_name);
echo "Your message has been Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
HTML FORM
<form action="contact_form.php" method="post" name="contact_form">
<p>First Name: <input name="first_name" type="text" />
Last Name: <input name="last_name" type="text" />
Phone Number: <input name="phone" type="text" placeholder="(999)999-9999" />
E-mail:<input name="email" type="text" placeholder="your#email.com" />
</p>
<p>
<textarea name="client_message" cols="5" rows="3" placeholder="Write your message here."></textarea>
</p>
<div class="6u 12u(2)">
<input type="checkbox" id="human" name="human" unchecked="">
<label for="human">I am not a robot.</label></div>
<div class="6u 12u(2)">
<input type="checkbox" id="robots" name="robots" unchecked="">
<label for="robots">I am a robot.</label>
</div>
<p>
<input type="submit" name="submit" id="submit" value="Send"/>
<input type="reset" name="reset" id="reset" value="Clear"/>
</p>
I've made a custom contact form with PHP working with HTML but I am getting some blank fields when sending an email.
Actually, I have made a table of 4 including Name, Email, Subject, and Message but the fields including Subject & Message are being sent empty.
I would appreciate any help given.
Thank you.
Html Code:
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" id="name" />
<input type="text" placeholder="email*" id="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" id="sub" />
</div>
<div class="form-block">
<textarea cols="1" rows="1" placeholder="Message*" id="message" ></textarea>
</div>
<div class="submit-btn">
<input type="button" id="submit" value="submit" class="detail-submit"/>
</div>
</form>
PHP:
<?php
$to = "My email";
$from = "";
$cc = "";
$subject = "Contact us form";
$errmasg = "";
$name = htmlentities(trim($_POST['name']));
$email = htmlentities(trim($_POST['email']));
$sub = htmlentities(trim($_POST['sub']));
$message = htmlentities(trim(nl2br($_POST['message'])));
if($email){
$message = "<table border='0' cellpadding='2' cellspacing='2' width='600'>
<tr><td>Name: ".$name." </td></tr>
<tr><td>Email: ".$email."</td></tr>
<tr><td>Subject: ".$sub."</td></tr>
<tr><td>Message:".$message."</td></tr>
</table>";
}else{
$errmasg = "No Data";
}
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'.$from . "\r\n";
$headers .= 'Cc:'.$cc . "\r\n";
if($errmasg == ""){
if(mail($to,$subject,$message,$headers)){
echo 1;
}else{
echo 'Error occurred while sending email';
}
}else{
echo $errmasg;
}
?>
You need to add an element NAME in the subject and message field.
Just replace your form code to below code:
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" id="name" />
<input type="text" placeholder="email*" id="email" />
</div>
<div class="form-block clearfix">
<input type="text" name="sub" placeholder="subject*" id="sub" />
</div>
<div class="form-block">
<textarea cols="1" rows="1" name="message" placeholder="Message*" id="message" ></textarea>
</div>
<div class="submit-btn">
<input type="button" id="submit" value="submit" class="detail-submit"/>
</div>
</form>
Each form element that you wish to appear in the POST array data when the form is submitted ( and thus to be available using $_POST['fieldname'] ) needs a name attribute. The ID attribute is optional but of limited use in many situations - certainly not required in a traditional form submission such as this..
The input button submit will NOT submit the form unless you do so with Javascript. It might be better to use a submit button as below.
<form action="mail.php" method="post">
<div class="form-block clearfix">
<input type="text" placeholder="name*" name="name" />
<input type="text" placeholder="email*" name="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" name="sub" />
</div>
<div class="form-block">
<textarea cols="100" rows="1" placeholder="Message*" name="message" ></textarea>
</div>
<div class="submit-btn">
<input type="submit" name="submit" value="Submit" class="detail-submit"/>
</div>
</form>
Not sure why you are having issues ~ perhaps the following will offer enlightenment. It is tested to the point of failing to send an email ( no local mailserver on dev machine at present ) and is an "all in one page" demo where the PHP emulates the original form action mail.php
<?php
/* this emulates mail.php */
error_reporting( E_ALL );
/* use a session variable */
session_start();
/* for testing single page demo */
$singlepage=true;
if( $_SERVER['REQUEST_METHOD']=='POST' ){
$to = "My email";
$from = $cc = '';
$subject = "Contact us form";
$errmasg = '';
/* filter POST data */
$args=array(
'name' => FILTER_SANITIZE_STRING,
'email' => FILTER_SANITIZE_EMAIL,
'sub' => FILTER_SANITIZE_STRING,
'message' => FILTER_SANITIZE_STRING
);
$_POST=filter_input_array( INPUT_POST, $args );
/* assign as variables */
extract( $_POST );
$name = htmlentities(trim($name));
$email = htmlentities(trim($email));
$sub = htmlentities(trim($sub));
$message = htmlentities(trim(nl2br($message)));
if( $email ){
$message = "<table border='0' cellpadding='2' cellspacing='2' width='600'>
<tr><td>Name: ".$name." </td></tr>
<tr><td>Email: ".$email."</td></tr>
<tr><td>Subject: ".$sub."</td></tr>
<tr><td>Message:".$message."</td></tr>
</table>";
}
# REMOVE THIS LINE or COMMENT IT OUT FOR REAL USAGE
#exit( sprintf("<pre>%s\n%s</pre>",$message, print_r( $_POST,true ) ) );
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'.$from . "\r\n";
$headers .= 'Cc:'.$cc . "\r\n";
if($errmasg == ""){
if( mail( $to, $subject, $message, $headers ) ){
$_SESSION['mailsent']=1;
}else{
$_SESSION['mailsent']=2;
}
}else{
$_SESSION['mailsent']=3;
}
/*
If you are using mail.php then use a `header` to redirect the user
back to the contact page - assumed to be called `contact.php`
*/
if( !$singlepage ) header( 'Location: contact.php' );
}
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>POST to email</title>
</head>
<body>
<!-- removed attribute action as this works on same page here -->
<form method="post">
<?php
if( !empty( $_SESSION['mailsent'] ) ){
switch( $_SESSION['mailsent'] ){
case 1:$message='Your message was sent successfully';break;
case 2:$message='Sorry - we had a problem sending your email';break;
case 3:$message='Bogus - no data';break;
}
printf( '<h1>%s</h1>', $message );
unset( $_SESSION['mailsent'] );
}
?>
<div class="form-block clearfix">
<input type="text" placeholder="name*" name="name" /><!-- element has a NAME -->
<input type="text" placeholder="email*" name="email" />
</div>
<div class="form-block clearfix">
<input type="text" placeholder="subject*" name="sub" />
</div>
<div class="form-block">
<textarea cols="100" rows="1" placeholder="Message*" name="message" ></textarea>
</div>
<div class="submit-btn">
<input type="submit" class="detail-submit" /><!-- a SUBMIT button -->
</div>
</form>
</body>
</html>
Typical output for debugging
Array
(
[name] => fred flintstone
[email] => fred#bedrock.com
[sub] => betty had better bake a cake
[message] => hey betty
)
Update:
I've added echo $errors to the end of my code. Now I am getting that all fields are required although all are filled:
} else {
echo $errors;
}
I've created a simple php e-mail form with this example (link). And jQuery form validator (link).
Now what I get after submiting a form is just a empty "contact-form-handler.php" page.
You can see the form live at: mantasmilka.com/#contactPage
What could be the problem? Below is my code.
contact-form-handler.php
<?php
$errors = '';
$myemail = 'mantas#mantasmilka.com';//<-----Put Your email address here.
if(empty($_POST['infoname']) ||
empty($_POST['infocompany']) ||
empty($_POST['infoemail']) ||
empty($_POST['infophone']) ||
empty($_POST['infodescription'])
)
{
$errors .= "\n Error: all fields are required";
}
$jobtype = $_POST['jobtype'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$infoname = $_POST['infoname'];
$infocompany = $_POST['infocompany'];
$infoemail = $_POST['infoemail'];
$infophone = $_POST['infophone'];
if (isset($_POST['infodescription'])) {
$infodescription = $_POST['infodescription'];
}
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$infoemail))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Jobtype: $jobtype \n Budget: $budget \n Location: $location \n Name: $infoname \n Company: $infocompany \n E-mail: $infoemail \n Phone: $infophone \n ".
"Message \n $infodescription";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $infoemail";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
// header('Location: http://www.mantasmilka.com/index.php');
header('Location: index.php');
exit();
} else {
echo $errors;
}
?>
my form in index.php:
<form id="contactform" method="post" name="contact_form" action="contact-form-handler.php">
<div class="left">
<fieldset class="jobtype">
<legend>Job type</legend>
<input type="radio" name="jobtype" id="project" value="project" required>
<label for="project">Project</label>
<input type="radio" name="jobtype" id="part-time" value="part-time" >
<label for="part-time">Part-time</label>
<input type="radio" name="jobtype" id="full-time" value="full-time" >
<label for="full-time">Full-time</label>
</fieldset>
<fieldset class="budget">
<legend>Budget</legend>
<input type="radio" name="budget" id="budget5k" value="budget5k" required>
<label for="budget5k">5k € ></label>
<input type="radio" name="budget" id="budget10k" value="budget10k" >
<label for="budget10k">5k - 10k €</label>
<input type="radio" name="budget" id="budget15k" value="budget15k" >
<label for="budget15k">15k € <</label>
</fieldset>
<fieldset class="location">
<legend>Location</legend>
<input type="radio" name="location" id="locremote" value="locremote" required>
<label for="locremote">Remote</label>
<input type="radio" name="location" id="loclocal" value="loclocal" >
<label for="loclocal">Local with relocation</label>
</fieldset>
</div>
<div class="right">
<fieldset class="contactinfo">
<legend>Your Contact Info</legend>
<div class="input-holder">
<input type="text" name="infoname" id="infoname" value="" required data-validation="alphanumeric">
<label for="infoname">Name</label>
</div>
<div class="input-holder">
<input type="text" name="infocompany" id="infocompany" value="" required data-validation="alphanumeric">
<label for="infocompany">Company</label>
</div>
<div class="input-holder">
<input type="text" name="infoemail" id="infoemail" value="" required data-validation="email">
<label for="infoemail">E-mail</label>
</div>
<div class="input-holder">
<input type="text" name="infophone" id="infophone" value="" required data-validation="number">
<label for="infophone">Phone</label>
</div>
<div class="input-holder textarea">
<textarea name="infodescription" form="contact_form" rows="4" required></textarea>
<label for="infodescription">Message</label>
</div>
<div class="input-holder submit">
<input type="submit" name="submit" value="Submit" required/>
</div>
</fieldset>
</div>
</form>
text field should look like this don't put form tag in here
<textarea name="infodescription" rows="4" required></textarea>
in php make the if statement like this the first ( opens the if statement the last ) closes it and take not of how i used the other brackets
if(
(empty($_POST['infoname'])) ||
(empty($_POST['infocompany'])) ||
(empty($_POST['infoemail'])) ||
(empty($_POST['infophone'])) ||
(empty($_POST['infodescription']))
)
{
$errors .= "\n Error: all fields are required";
}
The efficient way to solve the problem is:
$('#contactform').submit(function(ev) {
ev.preventDefault();
if($('#infodescription').val() == '')
{
alert('Description is required');
return false;
}
//add other validation
this.submit(); // If all the validations succeeded
});
By this you can avoid the unwanted server load.
I have set up a PHP mail form set up that only correctly outputs some of the variables entered in the form. It DOES mail the $name and $email variables, but not the $message variable.
The php to send the form is here:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST" ){
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
//sending email
require_once("siteIncludes/class.phpmailer.php");
$mail = new PHPMailer();
$email_body = "";
$email_body = $email_body . "Name: " . $name . $message . "<br />";
$email_body = $email_body . "Email: " . $email . "<br />";
$email_body = $email_body . "Message: " . $message;
$mail->SetFrom("$email,$name");
$address = "foo#bar.com";
$mail->AddAddress($address);
$mail->Subject = "Form Submission | ".$name;
$mail->MsgHTML($email_body);
if(!$mail->Send() ){
echo 'There was a problem sending the email: '.$mail->ErrorInfo;
exit();
}
header("Location: myContact.php?status=thanks");
exit();
};
?>
And the HTML that sets up the form is here:
<div id="contactFormWrap" class="span6 offset3">
<form method="post" action="myContact.php" id="contactForm">
<div>
<label for="name">Please leave your name</label>
<input type="text" name="name" id="name" value="" class="required" />
</div>
<div>
<label for="email">and your email</label>
<input type="text" name="email" id="email" value="" class="required email" />
</div>
<div>
<label for="subject">What is your message about?</label>
<input type="text" name="subject" id="subject" value="" class="required" />
</div> -->
<div>
<label for="message">and your message</label>
<textarea name="message" id="message" value="" rows="10" class="required"></textarea>
</div>
<div id="messageButtons">
<input type="submit" value="Submit" name="contactSubmit" id="contactSubmit" class="sendEmail btn" />
</div>
</form>
</div>
I hope that was enough information. Does anyone know why the $message variable isn't being output to the submitted email?
thanks
I think this is your problem:
value=""
The <textarea> tag does not have a value attribute, however different browsers have different ways of handling invalid code, so whatever browser you are using must be using the value found in this invalid attribute instead of what you type in the actual text box.
Just do:
<textarea name="message" id="message" rows="10" class="required"></textarea>
I decided to hard code a contact form for my Wordpress blog. I created a template and it is as follows. I just can't see the issue with it despite taking some time to look. Any help would be greatly appreciated. Also, I haven't forgotten to sanitise input. I'll add that function when i see the issue here. Thanks in advance...
Incidentally, I get this message: Parse error: syntax error, unexpected 'else' (T_ELSE) in F:\xampp\htdocs\new_theme\wp-content\themes\twentytwelve_child\contact.php on line 54
<?php /* Template Name: contact */?>
<?php get_header(); ?>
<?php
if(isset($_POST["submitted"])){
if($_POST["contactName"] === ""){
$nameError = "Please enter your name.";
$hasError = true;
}
else $name = $_POST['contactName'];
if($_POST["email"] === ""){
$emailError = "Please enter your email address.";
$hasError = true;
}
else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*#[a-z0-9.-]+\.[a-z]{2,4}$/i", $_POST['email'])) {
$emailError = "You entered an invalid email address.";
$hasError = true;
}
else $email = $_POST['email'];
if($_POST['comments'] === ""){
$commentError = "Please enter a message.";
$hasError = true;
}
else $comments = $_POST["comments"];
}
if(!isset($hasError)) {
$emailTo = "mathornley#gmail.com";
$subject = "From Android Scoop - From: $name";
$body = "Name: $name \n Email: $email \n Comments: $comments";
$headers = "From: $name <$emailTo> \n Reply-To: $email";
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
?>
<?php if(isset($emailSent) && $emailSent == true){ ?>
<div class="thanks">
<p>Thanks, your email was sent successfully.</p>
</div>
<?php } ?>
<?php else{?>
<?php if(isset($hasError){?> <p class="error">Sorry, an error occured.<p>
<div class="form_left">
<form action="<?php the_permalink();?>" method="post">
<label><span class="requiring">*</span>Name:</label>
<input type="text" name="contactName"/>
<?php if($nameError)?> <span class="error"><?=$nameError;?></span>
<label><span class="requiring">*</span>Email</label>
<input type="text" name="email"/>
<?php if($emailError)?><span class="error"><?=$emailError;?></span>
<label>Phone</label><input type="text" name="phone"/>
<input type="submit" value="Send your message"/>
<input type="hidden" name="submitted" value="true" />
</div>
<div class="form_right">
<label><span class="requiring">*</span>Message:</label>
<textarea name="comments" rows="20" cols="30" class="required requiredField"></textarea>
<?php if($commentError)?><span class="error"><?=$commentError;?></span>
</form>
</div>
<?php }} ?>
There are two syntax errors:
<?php }else{
if(isset($hasError)){?>
1,
<?php } ?>
<?php else{?>
You can't close the PHP tags, then open it again starting with else when using brackets. If you use alternative if/then statements, then this is possible
2,
if(isset($hasError)
You're missing the closing parenthesis on the if statement
Full:
<?php
if(isset($emailSent) && $emailSent == true){
echo '<div class="thanks"><p>Thanks, your email was sent successfully.</p></div>';
}else{
if(isset($hasError)){?>
<p class="error">Sorry, an error occured.<p>
<div class="form_left">
<form action="<?php the_permalink();?>" method="post">
<label><span class="requiring">*</span>Name:</label>
<input type="text" name="contactName"/>
<?php if($nameError)?> <span class="error"><?=$nameError;?></span>
<label><span class="requiring">*</span>Email</label>
<input type="text" name="email"/>
<?php if($emailError)?><span class="error"><?=$emailError;?></span>
<label>Phone</label><input type="text" name="phone"/>
<input type="submit" value="Send your message"/>
<input type="hidden" name="submitted" value="true" />
</div>
<div class="form_right">
<label><span class="requiring">*</span>Message:</label>
<textarea name="comments" rows="20" cols="30" class="required requiredField"></textarea>
<?php if($commentError)?><span class="error"><?=$commentError;?></span>
</form>
</div>
<?php
}
} ?>