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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:59:08+00:00 2026-05-20T03:59:08+00:00

hey guys, i know how to create a simple php file that mails some

  • 0

hey guys,
i know how to create a simple php file that mails some information to me.

However what I don’t know is how to call that php-file with jquery and hand over a variable.
Handing over a variable might work with isset()...

How can I call this PHP mailer from jquery and do that HIDDEN from the user. So there should not pop up a new window and shouldn’t be a page refresh or anything like that.

$('a.report').click(function(e) {
        e.preventDefault();
        var id = $(this).attr('href');

        //call mail script and pass along the "id" variable

        //change text (maybe in a callback function IF THE MAILING WAS A SUCCESS.
        $(this).parent().text('Thank you for reporting.');

    })

So I have this a.report Link which should trigger the email script. In my email script I need to access the “id” variable set in jquery. And it would even be nice to have a callback function if the php script did it’s thing so I could output “Thank you for reporting”.

How to do that?

Thank you guys.

  • 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-05-20T03:59:08+00:00Added an answer on May 20, 2026 at 3:59 am

    I would use $.post():

    <script type='text/javascript'>
    $(function(){
        function onReportPosted(data) {
            // data.status - either 'error' or 'success', from mailer.php
            // data.message - some text, from mailer.php
            $('.result').text(data.message);
        }
        $('a.report').click(function(e) {
            $('.result').text('sending report...');
            var data = {
                text: $('textarea[name=text]').val()
            };
            $.post(
                'mailer.php',
                data,
                onReportPosted,
                'json'
            );
            return false;
        });
    });
    </script>
    

    And in mailer.php:

    <?php
        if ( isset($_POST['text']) ) {
            // mail()...
            $result = array(
                'status' => 'success',
                'message' => 'thank you for reporting',
            );
        } else {
            $result = array(
                'status' => 'error',
                'message' => 'some error occurred',
            );
        }
        header('Content-Type: application/json');
        echo json_encode($result);
        exit;
    

    Update: here’s a way how to “tie” callback to a specific element:

    <script type='text/javascript'>
        $(function(){
            $('a.report').click(function(){
                var htmlElement = $(this).parent();
                var data = {
                    // ...
                };
                $.post(
                    document.location.toString(),
                    data,
                    function(data) {
                        htmlElement.html(data.message);
                    },
                    'json'
                );
                return false;
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys How do I use the PHP variable $contact['id'] in my ajax call?
hey guys, m building a web-page in that theres a tag which holds some
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey right now I'm using jQuery and I have some global variables to hold
Hey there guys and gals. I'm very new to php and am following various
Hey there! I'm doing this project and right now I'm trying to: create some
Hey guys, Im working with wpf 3d, im currently writing a program that will
Hey guys. I have a method that gets called each second which I want
hey guys, i know there are a lot of for-me-too-complicated versions of progress-bars for
hey guys, I've followed some tutorials online regarding creating and installing a windows service

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.