Error – email could not be sent – site may not be correctly configured – WordPress not sending emails on localhost – xampp

Is WordPress telling you that it is not set up to send emails? Read on.

This problem took me roughly 20hrs to get to the bottom of (I’m not embarrassed). If that sounds extreme, good! This is the type of problem that keeps you up at night. When you check so many different logs, so many times and still nothing.

In my defense, I was very strict about my standards for a solution. For example, I did not want to use a plugin (SMTP plugin or otherwise — unless absolutely necessary), and I didn’t want a duct tape fix, I actually wanted to get to the bottom of the issue and implement the most efficient fix possible (spoiler alert — I succeeded).

WordPress Error - email could not be sent - site may not be correctly configured to send emails - WordPress Email Localhost Issues
Facing WordPress Email Localhost Issues is not fun.

WordPress Email Localhost Issues

Actually, a big portion of the time was spent researching debugging methods. It’s ridiculous how much time I spent to fix this and what’s even more ridiculous is how simple the fix is.

The problem was that WordPress was trying to send an email form => wordpress@localhost. Which of course!! Is not a valid email address!!

Conveniently, that didn’t show up on ANY logs. How did I find out the issue? I installed the Check & Log Email plugin.

Serious props to the creators of this plugin. It’s what I should have used in the first place. Helped me find the issue in 5 minutes.

I also found another helpful script for debugging wp_mail. The implementation that worked well for me was as follows:

add_action( 'wp_loaded', 'mail_debugger' );

function mail_debugger() {
	$res = wp_mail($to, $subject, $message);
	debug_wpmail($res); // Will print_r array of errors

What’s the solution? Tell WordPress which email address to use in the wp_mail function. Fortunately, there’s an easy-to-use filter for that!

add_filter('wp_mail_from', 'get_admin_email');

if(!function_exists('get_admin_email')) {
	function get_admin_email($email) {
		$wp_from = get_option('admin_email');
		return $wp_from;

The code above tells WordPress to use the admin email address as the from address. If you want to use a custom email address, just return something else (see the example snippet below).

add_filter('wp_mail_from', 'get_admin_email');

if(!function_exists('get_admin_email')) {
	function get_admin_email($email) {
		return '';

You may also find some of my other configurations helpful. See below:


sendmail.ini (complete file) — Located in W:\xampp\sendmail

[mail function]
sendmail_path = "\"W:\xampp\sendmail\sendmail.exe\" -t"
mail.log = "W:\xampp\php\mklogs\phpmail.log"

php.ini (partial file) — Located in W:\xampp\php

It’s 1:20 in the morning as I type the sentence you just read. Yes, please read it again. Was it a waste of time troubleshooting this problem?

Not at all, as much as I wish I hadn’t spent so much time fixing what turned out to be a ridiculous problem, I learned so much about the phpmailer, SMTP, and Mercury (which I had never used before), and a whole lot more.

Hopefully, you found this post before spending 20 hours that you can never get back (I know you did because you’re not crazy).

Found this post about “Why WordPress is not sending emails on localhost” helpful? Let me know in the comments below 🙂 .

2 thoughts on “Error – email could not be sent – site may not be correctly configured – WordPress not sending emails on localhost – xampp”

Leave a Comment

Your email address will not be published. Required fields are marked *