Solved

wordpress email hook not working

Posted on 2012-04-08
4
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

628 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