Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

wordpress email hook not working

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

Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

What is that supposed to do and when?  Does it die silently or do you get an error message?
Avatar of stargateatlantis
stargateatlantis

ASKER

Its just a simple form that sends a email that is all.
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did that but it doesn't work.