2

I have a WordPress website installed on my localhost machine and I'm unable to send emails using the function wp_mail. I don't get any error but I can't receive my emails either? Can someone point me on the right direction? Here's an example of my code:

include("wp-mail.php");
$to = 'test@gmail.com';
$subject = 'Hello';
$message = 'Steve';

wp_mail( $to, $subject, $message );

Thanks

Dragon21
  • 17
  • 6
  • if you mean localhost as in the computer on your desktop, is it running a SMTP server configured to send email to remote domains? Try sending to root@localhost, that *should* work regardless. Linux these days usually includes EXIM and/or Sendmail. Configure that and it should work for remote domains.. just don't spam, you'll likely get blocked pretty quickly ;). – Duane Lortie Feb 17 '17 at 01:08

1 Answers1

1

wp_mail works similar to PHP's function mail. You can read more about it here. PHP mail function needs access to sendmail binary, as stated in docs, you shouldn't have this configured in localhost, that's why it fails to send emails.

In order to send emails when testing your website in localhost you should configure SMTP to send emails. There's this plugin caled WP Mail SMTP, you can install it here, I use it on most of my WordPress installations and works really grate.

It overides the wp_mail function and enables you to send emails using the Gmail SMTP server, for instance. You can use any SMTP server you want.

Dragon21
  • 17
  • 6
rafaelcpalmeida
  • 874
  • 1
  • 9
  • 28