-1

I have set up Wordpress locally and I am trying to send an email with this function:

$key = get_password_reset_key($user);
$url = 'http://frontend.web.node.net/reset-password?token=' . $key;
$to = $param['email'];
$subject = 'Passord reset';
$body = 'Du kan tilbakestille passordet ditt på denne lenken' . $url;
$headers = array('Content-Type: text/html; charset=UTF-8');
$sent = wp_mail($to, $subject, $body, $headers);

if (!$sent) {
  return ['error' => 'email was not sent'];
}

return ['success' => 'mail has been sent'];

But, when I am trying to send an email like that, the email is never sent, what I am doing wrong?

  • Does WP send email on it's own? (how is email setup?) - wpbeginner.com/wp-tutorials/… – nycynik Nov 7 '17 at 15:25
  • What mail server are you using? For this function to work, the settings SMTP and smtp_port (default: 25) need to be set in your php.ini file. – nycynik Nov 7 '17 at 15:28
0

wp_mail() uses phpMailer which defaults to localhost so if your development server is not configured as a mail server, the email won't fly.

Use the 'wp_mail_failed' action hook to get the WP_Error that's thrown so you can further troubleshoot the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.