Need help with contact form


I’ve tried creating a contact form using the following:

<form name="contact_form" method="post" action="">      
      <label for="name" class="fixedwidth">Your Name: </label>
      <input name="name" type="text" id="name" size="40" />
      <label for="name" id="name_error" class="error"><em>*</em></label>
      <label for="email" class="fixedwidth">Your Email: </label>
      <input name="email" type="text" id="email" size="40" />
      <label for="email" id="email_error" class="error"><em>*</em></label>
      <label for="subject" class="fixedwidth">Subject: </label>
      <input name="subject" type="text" id="subject" size="40" />
      <label for="subject" id="subject_error" class="error"><em>*</em></label>
      <label for="msg" class="fixedwidth">Your Message: </label>
      <textarea name="msg" id="msg" cols="40" rows="7"></textarea>
      <label for="msg" id="msg_error" class="error"><em>*</em></label>
    <div id="button">
      <input name="submit" type="submit" value="Submit" class="button" />
$(function() {
  $(".button").click(function() {
          var name = $("input#name").val();  
          if (name == "") {  
          return false;  
          var email = $("input#email").val();  
          if (email == "") {  
          return false;  
          var subject = $("input#subject").val();  
          if (subject == "") {  
          return false;  
		 var msg = $("textarea#msg").val();  
            if (msg == "") {  
          return false;
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
		//alert (dataString);return false;
      type: "POST",
      url: "process.php",
      data: dataString,
      success: function() {
        $('#contact').html("<div id='message'></div>");
        $('#message').html("<h2>Your Message Was Submitted!</h2>")
        .append("<p>We will be in touch with you soon.</p>")
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
    return false;
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
    $name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';}
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
    $email = stripslashes(strip_tags($_POST['email']));
} else {$email = 'Invalid email';}
if ((isset($_POST['subject'])) && (strlen(trim($_POST['subject'])) > 0)) {
    $phone = stripslashes(strip_tags($_POST['subject']));
} else {$phone = 'No Subject';}
if ((isset($_POST['msg'])) && (strlen(trim($_POST['msg'])) > 0)) {
    $phone = stripslashes(strip_tags($_POST['msg']));
} else {$phone = 'No message entered';}
<style type="text/css">
<table width="550" border="1" cellspacing="2" cellpadding="2">
  <tr bgcolor="#eeffee">
  <tr bgcolor="#eeeeff">
  <tr bgcolor="#eeffee">
  <tr bgcolor="#eeffee">
$body = ob_get_contents();

$to = '';
$email = '';
$fromaddress = "";
$fromname = "Online Contact";


$mail = new PHPMailer();

$mail->From     = "";
$mail->FromName = "Contact Form";
$mail->AddAddress("","Name 1");
$mail->AddAddress("","Name 2");

$mail->WordWrap = 50;

$mail->Subject  =  "Form:  Contact form submitted";
$mail->Body     =  $body;
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send()) {
    $recipient = '';
    $subject = 'Contact form failed';
    $content = $body;    
  mail($recipient, $subject, $content, "From: [email][/email]\\r\
Reply-To: $email\\r\
X-Mailer: DT_formmail");

Everything works from a users end- meaning the form validates that all fields have been filled in, and the user gets the confirmation message, without the page refreshing, that form was submitted… BUT I do not receive the emails. I’m assuming there must be an issue within the php.

What error(s) have I made???

Also, if you could assist with a better jquery validation, it would be greatly appreciated!!!


better contacts forms

Thanks for the reply and suggestion, but my goal is to become a developer and learn the coding.

if(!$mail->Send()) { 

According to that line, you will only get sent an email if PHPMailer FAILS to Send() the email.

If you want to reverse that decision, then remove that exclamation mark (!)

I bet you change your mind back after a while though :wink:

To understand what is going on at that line;

the logic in the if conditional check is as follows:

if( something is true ) {
then do this

Which is the same as saying

if( something is false ) {
then NEVER do this


if( PHPMailer Send is equal to true ){
send an email to me

Which is what you seem to want …

Hence with the ! negation imposed upon it:

if( it is true that PHPMailer Send is false ){
send an email to me

So remove the negation (!) and you will have reverted back to :

if( PHPMailer Send is equal to true ){
send an email to me

So all the time you are playing with true/false - that is what if() is assessing.

It might be *ugger to get your head round, but is a keystone of any language.


Thanks Cups! Great explanation which made perfect sense… and it worked!

Thanks again!