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

  • SEARCH
  • Home
  • 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 9147219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:56:05+00:00 2026-06-17T10:56:05+00:00

I have a PHP contact form that I’m using with jQuery’s AJAX method, but

  • 0

I have a PHP contact form that I’m using with jQuery’s AJAX method, but I’m getting very strange results with the “success:” function.

Here’s the PHP contact form:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$msg = "Name: $name\n";
$msg .= "Email: $email\n";
$msg .= "Number: $number\n\n";
$msg .= "$message\n";
$recipient = "[recipients here]";
$subject = "Contact Us - $name";
$mailheaders = "From:$email";
$success = mail($recipient, $subject, $msg, $mailheaders);

if ($success) {
    echo ('Correct');
} else {
    echo ('Failed');
}
header("Location: [website address here]");
?> 

Here’s the jQuery AJAX method:

$("#contact-form").submit(function (event) {
    $.ajax({
        type: "POST",
        url: '/lib/mailer.php',
        data: {
            name: $("#name").val(),
            email: $("#email").val(),
            number: $("#number").val(),
            message: $("#message").val()
        },
        success: function (data) {
            //$("#contact-form")[0].reset();
            alert(data);

            if(data === 'Correct') {
                alert('Data is correct');
            }
            else if (data !== 'Correct') {
                alert('Data is not equal to correct');
            }
            else {
                alert('Else statement');
            }
        }
    });

    event.preventDefault();
    return false;
});

Now, when I fill in the form and click submit, the PHP receives the right data and successfully sends the email, and echo’s “Correct”. An alert pops up saying “Correct”. But then, instead of the next alert being “Data is correct”, it is “Data is not equal to correct”.

I have no idea what’s going on here for that to happen. I’m assuming I must be making a really stupid mistake somewhere but can’t seem to figure it out.

  • 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-17T10:56:06+00:00Added an answer on June 17, 2026 at 10:56 am

    It is not matching the word.
    Use

    if($.trim(data) == 'Correct')
    

    Hope it will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a contact form that I'm writing using jQuery and PHP. Below is
I have a form that validates using jquery. The form's id is contact and
I am new to PHP, but, I have a simple contact form that is
i have developed a simple php contact form, that's working fine, but i am
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
I have a contact page (contact.php) that sends a form (formsend.php) when people fill
I have a PHP contact form on my website. I have been using it
I have a small contact form: <form method=post action=contact.php name=contactform id=contactform> <fieldset> <legend>Please fill
I have file with name contact.php, inside I have form: <form method=post name=kontakt action=send_mail.php>
I have a simple PHP contact form on my website that I'm building. At

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.