Calling wp_mail() with AJAX
-
I’m running up against a undefined function wp_mail() error I could use some help with.
The script “approve_ajax” is enqueued via the following:
add_action( 'wp_enqueue_scripts', 'approve_ajax' ); function approve_ajax() { wp_enqueue_script( 'approve_ajax', get_template_directory_uri() . '/list/ajax.js', array('jquery'), '1.0', true ); }
The contents of ajax.js are simple, basically onclick it is triggered, and calls the server-approve.php script:
function approve(user,email) { $.ajax({ url: "/wp-content/themes/bibliofile/list/server-approve.php", type: "POST", data: { 'username': user, 'approve': '1', 'emailaddress': email }, success: function(data){ // there's some stuff here } }); };
Server-approve.php does a bunch of stuff but most importantly:
if (isset($_POST['username'])) { wp_mail($_POST['emailaddress'], $subject, $message); }
I can’t seem to figure out how to get wp_mail() to work here. I get a 500 server error each time. It works fine anywhere that doesn’t involve AJAX.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Calling wp_mail() with AJAX’ is closed to new replies.