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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:38:44+00:00 2026-06-17T03:38:44+00:00

i am using correct code , still the ajax request is not sending the

  • 0

i am using correct code, still the ajax request is not sending the email content– Can anyone have a look and suggest me what i can do better to get an email

Here is the form :

<form method="post" action="process.php">
    <div class="element">
        <label>Name</label>
        <input type="text" name="name" class="text" />
    </div>
    <div class="element">
        <label>Email</label>
        <input type="text" name="email" class="text" />
    </div>
    <div class="element">
        <label>Phone </label>
        <input type="text" name="website" class="text" />
    </div>
    <div class="element">
        <label>Comment</label>
        <textarea name="comment" class="text textarea" /></textarea>
    </div>
    <div class="element">

        <input type="submit" id="submit"/>
        <div class="loading"></div>
    </div>
    </form>

Here is the ajax request: —

<script type="text/javascript">
$(document).ready(function() {

    //if submit button is clicked
    $('#submit').click(function () {        

        //Get the data from all the fields
        var name = $('input[name=name]');
        var email = $('input[name=email]');
        var website = $('input[name=website]');
        var comment = $('textarea[name=comment]');

        //Simple validation to make sure user entered something
        //If error found, add hightlight class to the text field
        if (name.val()=='') {
            name.addClass('hightlight');
            return false;
        } else name.removeClass('hightlight');

        if (email.val()=='') {
            email.addClass('hightlight');
            return false;
        } else email.removeClass('hightlight');

        if (comment.val()=='') {
            comment.addClass('hightlight');
            return false;
        } else comment.removeClass('hightlight');

        //organize the data properly
        var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + 
        website.val() + '&comment='  + encodeURIComponent(comment.val());

        //disabled all the text fields
        $('.text').attr('enabled','false');

        //show the loading sign
        $('.loading').show();

        //start the ajax
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "process.php", 

            //GET method is used
            type: "GET",

            //pass the data         
            data: data,     

            //Do not cache the page
            cache: false,

            //success
            success: function (html) {              
                //if process.php returned 1/true (send mail success)
                if (html==1) {                  
                    //hide the form
                    $('.form').fadeOut('slow');                 

                    //show the success message
                    $('.done').fadeIn('slow');

                //if process.php returned 0/false (send mail failed)
                } else alert('Sorry, unexpected error. Please try again later.');               
            }       
        });

        //cancel the submit button default behaviours
        return false;
    }); 
}); 
</script>

and process.php as

<?php

//Retrieve form data. 
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$website = ($_GET['website']) ?$_GET['website'] : $_POST['website'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];

//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;

//Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.'; 
if (!$comment) $errors[count($errors)] = 'Please enter your comment.'; 

//if the errors array is empty, send the mail / no errors found
if (!$errors) {


//recipient
    $to = 'info@abc.com';   
    //sender
    $from = $name . ' <' . $email . '>';

    //subject and the html message
    $subject = 'Comment from ' . $name; 
    $message = '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
    <table>
        <tr><td>Name</td><td>' . $name . '</td></tr>
        <tr><td>Email</td><td>' . $email . '</td></tr>
        <tr><td>Phone</td><td>' . $website . '</td></tr>
        <tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
    </table>
    </body>
    </html>';

    //send the mail
    $result = sendmail($to, $subject, $message, $from);

    //if POST was used, display the message straight away
    if ($_POST) {
        echo 'Thank you! We have received your message.';

    //This one for ajax
    //1 means success, 0 means failed
    } else {
        echo '1';   
    }


} else {
    //display the errors message
    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
    echo '<a href="yourdomain.com">Back</a>';
    exit;
}


//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";

    $result = mail($to,$subject,$message,$headers);

    if ($result) return 1;
    else return 0;
}



?>

Any help in the end ? Thankyou

  • 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-17T03:38:46+00:00Added an answer on June 17, 2026 at 3:38 am

    Please browse process.php?name=jone&email=john@example.com&website=www.blabla.com&comment=blablabla to know if the problem is in the server side script.

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

Sidebar

Related Questions

Using Codesourcery arm-linux-eabi crosscompiler and have problems with the compiler not executing certain code
I am looking at code which has the correct using statements declared but yet
I'm trying to write this code using mostly arrays. I'm trying to get Correct
Not sure if I am using the correct term, but it's not child/parent since
I'm using .NET 4 and getting Input string not in correct format error when
I am trying to load data using an AJAX request in my Chrome Extension.
My code is such that before firing an ajax request, the table row has
Using jquery1.7.1 and django1.3 ,I was trying to make a post request through ajax,in
Alright, I'm making a website using PHP/HTML, and I have some backend AJAX to
I have problem firing an ajax request with Primefaces <f:metadata> <f:viewParam name=token value=#{clientBean.token}/> <f:event

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.