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 8055591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:26:15+00:00 2026-06-05T08:26:15+00:00

I have a mail.php file that gets called by an ajax script. For completeness,

  • 0

I have a mail.php file that gets called by an ajax script. For completeness, the ajax script is attached below. All the mail.php file does is perform some server-side validation, and if everything passes, sends an email with mail() and the data sent from the ajax request.

What I want to do is perform some additional javascript actions based on the response of the request. You can see that at its current state, the response of the request is simply echo’d to the screen, which is fine. But now I want to modify HTML elements based on the response.

For example, say I want to append an image called “OK” to the page if the mail was sent, and else append an image called “FALSE” to the page if the mail was not sent. What I’d like to do (in pseudocode) is this:

if ( request is OKAY ) $('.contact').append('<img src"OK"');
else ( $('.contact').append('<img src="BAD''); 

Is there any way to perform this?

Thanks!

The ajax script is shown below:

$('.submit').click(function() {
    $('div.load').html('<img src="images/load.gif" alt="Loading..." id="loading" />'); 

    //creation of variables to send
    var name = $('#name').val();
        email = $('#email').val();
        phone = $('#phone').val();

    $.ajax({
        url: 'mail.php',
        type: 'POST',
        data: 'name=' + name + '&email=' + email + '&phone=' + phone,

        success: function(result) {
            $('p.error,p.correct').remove();
            $('.contact').append(result);
            $('#loading').fadeOut(500, function() {
                $(this).remove();
            });

        }
    });

    return false; 
});
  • 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-05T08:26:16+00:00Added an answer on June 5, 2026 at 8:26 am

    Assuming your PHP responds with the text “OKAY”:

    if (result==="OKAY")
       $('.contact').append('<img src"OK" />');
    else
       $('.contact').append('<img src="BAD" />');
    

    Or:

    $('.contact').append('<img src"' + (result==="OKAY"?'OK':'BAD') + '" />');
    

    An alternative is to update your PHP so that it returns html that includes both a message and the image, e.g., on success it could return:

    Your request was successful. <img src="OK" />
    

    “I should mention that I’d like to keep the current response there as well to make sure that non-JS users also get the appropriate message”

    Non-JS users will not be getting anything because your Ajax code uses JS…

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

Sidebar

Related Questions

I have a small script which im using to test PHP mail(), as below:
I have an jquery ajax request that calls a PHP script that will send
I have a script that uses PHP mail() function to send emails: mail(me@mydomain.com, Subject,
I have the following mail.php file : <?php $name = $_POST['name']; $to = $_POST['to'];
I have a php mail script sitting on a LAMP vps server. The script
We currently have a working php mail script, this works fine and as we
I have written a php e-mail processing client that uses the IMAP protocol. I
I have a PHP application that sends email using the pear Mail function. Unfortunately
I have a php file that I am trying to send the output in
I have a form on a page that sends data to php file via

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.