Mark Tait
Mark Tait

Reputation: 643

Issue sending email from Javascript with WP SMTP Mail

I have successfully setup the WP SMTP Mail plugin - test emails (from the plugin setup page) come through no problem.

I'm now trying to send a simple email from Javascript from a page on the same WordPress site. The code is:

<script>
function sendEmail() {
  var data = {
    'to': '[email protected]',
    'subject': 'Hello',
    'message': 'Hello, world!'
  };

  jQuery.post('/wp-admin/admin-ajax.php?action=wp_smtp_mail_send', data)
    .done(function(response) {
      console.log('Email sent successfully.');
    })
    .fail(function(error) {
      console.log('Error sending email.');
    });
}

sendEmail();
</script>

It returns: Error sending email.

Can you see anything wrong with my code?

Thanks, Mark

Upvotes: 0

Views: 216

Answers (0)

Related Questions