stargateatlantis
asked on
wordpress email hook not working
I am having trouble getting the following WordPress hook working here is the following code
The Jquery 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();
}
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();
});
});
What is that supposed to do and when? Does it die silently or do you get an error message?
ASKER
Its just a simple form that sends a email that is all.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did that but it doesn't work.