0

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': 'mark1345@gmail.com',
    '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

Mark Tait
  • 545
  • 3
  • 12
  • 22
  • There's nothing wrong with your JS code (apart from it being a wide-open spam gateway), but the error is coming from the back end, and you've not shown us the code for that. – Synchro May 25 '23 at 15:13
  • Hi - the backend is the WP SMTP Mail plugin- what would help from there? – Mark Tait May 25 '23 at 15:41
  • As far as I’m aware the smtp mail plugin just provides smtp config, and doesn’t handle requests or actually send messages – I think you have to call it from other code. Either way, the plug-in docs should cover it. – Synchro May 26 '23 at 20:38

0 Answers0