Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:06:33+00:00 2026-06-12T16:06:33+00:00

I am trying to create a contact form that collects a name, email, message

  • 0

I am trying to create a contact form that collects a name, email, message type and message from a form. So far the validation of the fields, getting the information and sending the email all work correctly. The main problem I can’t seem to fix is that once the information is submitted There is suppose to be a success message that is shown once the email is sent. This is where my problem is.

Here is the function that is suppose to do all the work.:

JQuery

// make our ajax request to the server
function submitForm(formData) {

    $.ajax({    
        type: 'POST',
        url: 'Scripts/send_email.php',
        dataType: 'json',       
        data: formData,
        cache: false,
        /*timeout: 8000, // timeout after 8 seconds*/
        success: function(data,textStatus,XMLHttpRequest) {
            $('form #error-div').removeClass('').addClass((data.error === true) ? 'xmark-img' : 'check-img');

                if ($('form #error-div').hasClass('check-img')) {
                    $('form #error-div').addClass('success').html(data.msg).fadeIn('fast'); 
                }

                $('form').slideUp().hide();
                $('form').find('span').hide();
                $('form').find('label').hide();
                $('form').find('input').hide();
                $('form').find('select').hide();
                $('form').find('textarea').hide();

                setTimeout($('form #error-div').fadeOut('slow'), 4000); 
                return true;        
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
                $('form #error-div').removeClass('').addClass('xmark-img').addClass('error-box').html('');
                $('form #error-div').html('There was an ' + errorThrown +
                                          ' error due to a ' + textStatus + 
                                          ' condition.'+ 'XMLHttpRequest: ' + XMLHttpRequest[0] + 
                                          ' Error Thrown: ' + errorThrown + '<br/>' + 
                                          ' textStatus:  ' + textStatus + ' <br />msg: ' 
                                          + msg + '<br />data: ' + data).fadeIn('fast')

            return false;
        },              
        complete: function(XMLHttpRequest, status) {
                $('form')[0].reset();           
        }
    }); 
};

Right now after the form is submitted the error-div shows the sending message animated gif and I do receive the email. But, it does not execute the success or error callback. Using firebug I also get an error “TypeError: data is null”. I’m not sure what I could be doing wrong since the email does get sent.


PHP Script

<?php 
sleep(3);

//Sanitize incoming data and store in variable
$name = trim(stripslashes(htmlspecialchars($_POST['name'])));
$email = trim(stripslashes(htmlspecialchars($_POST['email'])));
$message = trim(stripslashes(htmlspecialchars($_POST['message'])));
$message_type = trim(stripslashes(htmlspecialchars($_POST['message_type'])));   

$humancheck = $_POST['humancheck'];
$honeypot = $_POST['honeypot'];

if ($honeypot == 'http://' && empty($humancheck)) {         
        //Validate data and return success or error message
        $error_message = '';    
        $reg_exp = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[\.]{1}[a-zA-Z]{2,4}$/";

        if (!preg_match($reg_exp, $email)) {
                $error_message .= "You must provide a valid e-mail address <br/>";             
        }

        if (empty($name)) {
                $error_message .= "You must include your name <br/>";
        }
        if (empty($message_type)) {
                $error_message .= "You must select a message type for your message. <br/>";
        }               
        if (empty($message)) {
                $error_message .= "You must enter a message. <br/>";
        }       
        if (!empty($error_message)) {
                $return['msg'] = 'Error: The request was successful but your form is not filled out correctly. '.$error_message;
                $return['error'] = true;
                exit();
        }else {
                    $ToEmail = "tony.hall@tonyhallportfolio.com";
                    $EmailSubject_Response = $message_type." from ".$name." (".$email.")"; 

                    $mailheader_Response = "From: ".$email."\r\n";
                    $mailheader_Response .= "To: ".$ToEmail."\r\n"; 
                    $mailheader_Response .= "Reply-To: ".$email."\r\n";
                    $mailheader_Response .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

                    $MESSAGE_BODY_Response  = "<html><head><link rel='stylesheet' type='text/css' href='http://tonyhallportfolio.com/CSS/email_style.css' /></head><body>";
                    $MESSAGE_BODY_Response .= "<div class='header'><img src='http://tonyhallportfolio.com/images/logo-ns.png'/></div>\n";
                    $MESSAGE_BODY_Response .= "<hr/>\n";
                    $MESSAGE_BODY_Response .= "<div class='content'><h3>E-Mail Message via Tonyhallportfolio.com </h3>";
                    $MESSAGE_BODY_Response .= "<h4>Name: </h4>".$name."\n"; 
                    $MESSAGE_BODY_Response .= "<h4>Email: </h4>".$email."\n"; 
                    $MESSAGE_BODY_Response .= "<h4>Message Details: </h4>".nl2br($message)."</div>"; 
                    $MESSAGE_BODY_Response .= "<body/><html/>";

                    mail($ToEmail, $EmailSubject_Response, $MESSAGE_BODY_Response, $mailheader_Response) or die ("Failure");

                    if($message_type == "Website Inquiry"){
                        $EmailSubject_Inq = "Conformation of ".$message_type." sent via tonyhallportfolio.com"; 

                        $mailheader_Inq = "From: ".$ToEmail."\r\n";
                        $mailheader_Inq .= "To: ".$email."\r\n"; 
                        $mailheader_Inq .= "Reply-To: ".$ToEmail."\r\n";
                        $mailheader_Inq .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

                        $MESSAGE_BODY_Inq  = "<html><head><link rel='stylesheet' type='text/css' href='http://tonyhallportfolio.com/CSS/email_style.css' /></head><body>";
                        $MESSAGE_BODY_Inq .= "<div class='header'><img src='http://tonyhallportfolio.com/images/logo-ns.png'/></div>\n";
                        $MESSAGE_BODY_Inq .= "<hr/>\n";
                        $MESSAGE_BODY_Inq .= "<div class='content'>"."<p>Thank you for reaching out to me in order to build a website for yourself or your business. This email confirms that your message has been sent. Please allow me ample time to respond back to you as I may have others inquiring for my services. I will make sure to review the information you sent me and respond in a reasonable amount of time. Thanks again for your inquiry.</p>";

                        $MESSAGE_BODY_Inq .= "<h3>".$message_type." for Tony Hall via Tonyhallportfolio.com </h3>";
                        $MESSAGE_BODY_Inq .= "<h4>Name: </h4>".$name."\n"; 
                        $MESSAGE_BODY_Inq .= "<h4>Email: </h4>".$email."\n"; 
                        $MESSAGE_BODY_Inq .= "<h4>Message Details: </h4>".nl2br($message)."</div>"; 
                        $MESSAGE_BODY_Inq .= "<body/><html/>";

                        mail($email, $EmailSubject_Inq, $MESSAGE_BODY_Inq, $mailheader_Inq) or die ("Failure");

                        $return['msg'] = '<h3>'.$name.' ,Thank you for your message. </h3>';    
                        $return['error'] = false;

                    }else{
                        $EmailSubject_msg = "Conformation of ".$message_type." sent via tonyhallportfolio.com"; 

                        $mailheader_msg   = "From: ".$ToEmail."\r\n";
                        $mailheader_msg  .= "To: ".$email."\r\n"; 
                        $mailheader_msg  .= "Reply-To:".$email."\r\n";
                        $mailheader_msg  .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

                        $MESSAGE_BODY_msg  = "<html><head><link rel='stylesheet' type='text/css' href='http://tonyhallportfolio.com/CSS/email_style.css' /></head><body>";
                        $MESSAGE_BODY_msg .= "<div class='header'><img src='http://tonyhallportfolio.com/images/logo-ns.png'/></div>\n";
                        $MESSAGE_BODY_msg .= "<hr/>\n";
                        $MESSAGE_BODY_msg .= "<div class='content'>"."<p>Thank you for leaving me a message on my E-Portfolio website. This email confirms that your message has been sent. I will make sure to review your message and take your comments and/or suggestions in consideration to help improve the site. Your input is greatly appreciated.</p>";

                        $MESSAGE_BODY_msg .= "<h3>".$message_type." for Tony Hall via Tonyhallportfolio.com </h3>";
                        $MESSAGE_BODY_msg .= "<h4>Name: </h4>".$name."\n"; 
                        $MESSAGE_BODY_msg .= "<h4>Email: </h4>".$email."\n"; 
                        $MESSAGE_BODY_msg .= "<h4>Message Details: </h4>".nl2br($message)."</div>"; 
                        $MESSAGE_BODY_msg .= "<body/><html/>";

                        mail($email, $EmailSubject_msg, $MESSAGE_BODY_msg, $mailheader_msg) or die ("Failure");

                        $return['msg'] = $name.' ,Thank you for your message.'; 
                        $return['error'] = false;
                        exit(); 
                    }
             }          


}else {
    $return['msg'] = 'There was a problem with your submission. Please try again.';
    $return['error'] = true;
    exit(); 
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:06:35+00:00Added an answer on June 12, 2026 at 4:06 pm

    You’re returning a $return array there, you’ll need to converti it into JSON format before echoing it like this:

    echo json_encode($return);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set up validation on a simple contact form that is
I'm playing around with MVC3 and trying to create a simple contact form that
I'm trying to create a simple contact form for my MVC app. So far
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I would like to create a plugin that uses the contact form 7 hook,
I am new to ASP.NET, and I am trying to create a contact form
New to rails 3 I would like to create a contact form that people
I'm trying to create a text widget that includes an entry form on top
I am trying to create my own basic form validation without having to resort
I'm trying to create a contact form using phpMailer and I get in firebug

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.