• Sending normal messages using SMTP works perfectly. However, when attempting to reset a password on the WordPress login page, I encounter the error message: ‘Error: The email could not be sent. Your site may not be correctly configured to send emails.’ It seems that WordPress does not utilize SMTP for password resets. Instead, it uses the following mail settings:

    Current mail settings:

    • Mailer: mail
    • SendMail path: /usr/sbin/sendmail
    • Host: localhost
    • Port: 25

    These settings suggest that WordPress is configured to use the server’s default mail handling (sendmail) rather than SMTP, which may be why password reset emails are not being sent.

    add_action('phpmailer_init', 'my_phpmailer_smtp');

    function my_phpmailer_smtp($phpmailer) {

    ? ? error_log('my_phpmailer_smtp function is called');

    ? ? $phpmailer->isSMTP();

    ? ? $phpmailer->Host = SMTP_SERVER;

    ? ? $phpmailer->SMTPAuth = SMTP_AUTH;

    ? ? $phpmailer->Port = SMTP_PORT;

    ? ? $phpmailer->Username = SMTP_USERNAME;

    ? ? $phpmailer->Password = SMTP_PASSWORD;

    ? ? $phpmailer->SMTPSecure = SMTP_SECURE;

    ? ? $phpmailer->From = SMTP_FROM;

    ? ? $phpmailer->FromName = SMTP_NAME;

    ? ? $phpmailer->SMTPDebug = SMTP_DEBUG; // Set to 1 or 2 for debugging (only for testing)

    ? ? $phpmailer->CharSet = 'UTF-8';

    }
    • This topic was modified 4 months, 1 week ago by saadchellah.
Viewing 1 replies (of 1 total)
  • Every email sent from WordPress is sent via wp_mail(). The hook you used phpmailer_init can also be found there. It is only actually not called if there was an error when setting the sender address. See: https://github.com/WordPress/WordPress/blob/master/wp-includes/pluggable.php#L174

    I would rather ask when your hook is executed? Are you loading it via a plugin and is it possibly dependent on another hook?

    Another note: why don’t you use a ready-made SMTP plugin like WP Mail SMTP? From a developer’s point of view, I can understand trying it yourself. But then you could also debug the above-mentioned code in the core to find out for yourself where the processing is failing.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.