Solved

wordpress email hook not working

Posted on 2012-04-08
4
359 Views
Last Modified: 2012-05-12
I am having trouble getting the following WordPress hook working here is the following code

//if you want none logged in users to access this function use this hook
add_action('wp_ajax_nopriv_mail_before_submit', 'send_AJAX_mail_before_submit');

function send_AJAX_mail_before_submit(){
    check_ajax_referer('my_email_ajax_nonce');
    if (isset($_POST['action']) && $_POST['action'] =="mail_before_submit"){

    //send email  wp_mail( $to, $subject, $message, $headers, $attachments ); ex:
        wp_mail('email@domain.com','this is the email subject line','email message body');
        echo 'email sent';
        die();
    }
    echo 'error';
    die();
}

Open in new window



The Jquery Code
jQuery(document).ready(function(){

        jQuery('#donationForm').submit(function() {

        // send email to client before moving onto worldpay payment form
        var data = {
            action: 'mail_before_submit',
            Whatever: 1234,
            _ajax_nonce: <?php echo wp_create_nonce( 'my_email_ajax_nonce' ); ?>
        };
        jQuery.post("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php", data, function(response) {
                alert('Got this from the server: ' + response);
        });
        //  send data to worldpay....
       // this.submit();

        });

    });

Open in new window

0
Comment
Question by:stargateatlantis
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 37841052
What is that supposed to do and when?  Does it die silently or do you get an error message?
0
 

Author Comment

by:stargateatlantis
ID: 37842063
Its just a simple form that sends a email that is all.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 37843546
What happens if you change $_POST to $_REQUEST in the first code snippet?
0
 

Author Comment

by:stargateatlantis
ID: 37843950
I did that but it doesn't work.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question