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:
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 notuser@example
orUser <[email protected]>
; otherwise, the email will not be sent.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.