WordPress anyone can register, but no email confirmation

Many times it has happened to me that my WordPress installation properly send emails using wp_mail directly, specifing also the…

Agosto 25, 2015

Many times it has happened to me that my WordPress installation properly send emails using wp_mail directly, specifing also the headers parameter with the proper From syntax followed by the email address.
But when I use the “anyone can register” checkbox and try to register a new user from the url http://yourdomain.it/wp-login.php?action=register I don’t receive any email and can’t use the users (neither for the user nor for the admin).
So I’ve investigated a little bit more and I’ve found that the wp_new_user_notification function in the wp-includes/pluggable.php core file do not have a default value for From header. This let the PHP use the parameter in the php.ini file (I think) which on many server is not configured for your web sites, and so your emails are not sent.
To fix this, force wp_mail to use a From header by adding this two functions on your functions.php file.

add_filter( 'wp_mail_from', 'force_from' );
function force_from( $email ) {
	return "noreply@yourdomain.it";
}

add_filter( 'wp_mail_from_name', 'force_from_name' );
function force_from_name( $name ) {
	return "Wordpress of Your Domain";
}

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

WP doesn’t send email? try this

Snippets for sending emails with Wordpress

Febbraio 8, 2020

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

Settembre 22, 2015

Social buttons: the fastest way for WordPress, without plugins

NOTE: the code in this post is written for WordPress but you can easily translate it in any language. You’re here…

Settembre 15, 2015

Optimize WordPress, a long list of tips

In the above image you can see your WordPress before reading this post, and after the optimizations you will make…

Limit the number of categories for posts in WordPress

CHOOSE ONLY ONE CATEGORY WORDPRESS If you need to limit the number of categories used by the authors of your…

Settembre 14, 2015

Remove archive pages in WordPress, how to

I think that in most blogs (that is not all) archive pages are redundant content and there’s no need to…

Settembre 8, 2015