Skip to main content
2 of 4
Better answer
Sally CJ
  • 39.3k
  • 2
  • 25
  • 46

Where is the problem? Am I doing something wrong?

Your code seems fine to me, so despite I can't give you a definitive answer on what/where exactly is the problem, I thought these might help you troubleshoot the issue:

  1. First and foremost, check your configuration — e.g. did you use the correct username/email, password, host?

    And make sure the SMTP_FROM value is a valid email addresss — e.g. [email protected] and not user@example or User <[email protected]>; otherwise, the email will not be sent.

  2. If you're sure the configuration is good, then because you're using SMTP, try enabling debugging like so — add this to your my_phpmailer_example() function:

    // Note: I assumed you're using at least WordPress version 5.5.0
    
    $phpmailer->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
    

Then visit the WordPress's password reset page and try to reset your password, and on the next page, if PHPMailer was unable to send the email, then you'd see the error message displayed at the top of the page.

  • If you see an error, then you'd need to try fixing the issue on your own, but there's an article by the PHPMailer team which might help you.

  • If you don't see any error, then try deactivating all plugins and try to reset your password. Does the issue persist?

    If no, then you'd need to find which plugin is causing the issue and then contact their support for assistance.

Sally CJ
  • 39.3k
  • 2
  • 25
  • 46