Solved

wordpress email hook not working

Posted on 2012-04-08
4
370 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

734 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