Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

wordpress email hook not working

Posted on 2012-04-08
4
Medium Priority
?
390 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 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…
Suggested Courses

972 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