wp_mail script with jQuery post

I need to send an email from a page when a form is submitted.

I thought I’d use jQuery post but I’m not really sure where to start. Would I use wp_mail()? And if so how could it be called?

Sorry if that seems vague. Just trying to send an email to the client before a form posts its data to another site;

$('#donationForm').submit(function() {

// send email to client before moving onto worldpay payment form


//  send data to worldpay....
this.submit();

});

2 Answers
2

Basically, you can use JavaScript to post to a WordPress function, then the WordPress function can invoke wp_mail() to send the message.

A great place to start would be the useful AJAX in Plugins article on the Codex. It walks you through all the steps required to add your JavaScript on the front-end, your PHP on the back-end, and everything you need to do to tie the two together.

Leave a Comment