Good Day Everyone,
I am trying my New User Registration form Plugin on a live site, but the emails are not being sent.
I save the new user using:
if (empty($errors)) {
$myplugin_newuser = wp_insert_user(array(
'user_login' => $user_login,
'user_email' => $user_email,
'nickname' => $user_nickname,
'user_pass' => $user_pass,
'first_name' => $user_firstname,
'last_name' => $user_lastname,
'description' => $user_bio,
'user_url' => $user_url,
'user_registered' => date('Y-m-d H:i:s'),
'role' => 'subscriber'
));
After that I follow the official way of WordPress to change the New User Notification found here:
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
$user = new WP_User( $user_id );
$user_login = stripslashes( $user->user_login );
$user_email = stripslashes( $user->user_email );
$message = sprintf( __('New user registration on %s:'), get_option('blogname') ) . "\r\n\r\n";
$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n\r\n";
$message .= sprintf( __('E-mail: %s'), $user_email ) . "\r\n";
@wp_mail(
get_option('admin_email'),
sprintf(__('[%s] New User Registration'), get_option('blogname') ),
$message
);
if ( empty( $plaintext_pass ) )
return;
$message = __('Hi there,') . "\r\n\r\n";
$message .= sprintf( __("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
$message .= wp_login_url() . "\r\n";
$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n";
$message .= sprintf( __('Password: %s'), $plaintext_pass ) . "\r\n\r\n";
$message .= sprintf( __('If you have any problems, please contact me at %s.'), get_option('admin_email') ) . "\r\n\r\n";
$message .= __('Adios!');
wp_mail(
$user_email,
sprintf( __('[%s] Your username and password'), get_option('blogname') ),
$message
);
}
}
I know it's said that if the password information is not passed the email will not be sent to the user, but I don't seem to be receiving the email to my admin email either.
But from my understanding of the code if '' is given that would mean it's empty but the information is passed so the email should be sent.
Is it the way I Insert the new user that is not correct? Or is it something else that am missing.
The tests were made, normal emails are being sent properly with my WP Mail Bank plugin.
Just to make sure I also tried to call the function itself, as per the line above I am passing the user_login and user_pass information:
wp_new_user_notification( $user_login, $user_pass);
EDIT Now that I use the function (which fixed a quarter of the issue), the admin receives the email, but without any details of the user_login or $user_pass (which are variables, as you can see above, I use to send the information WordPress to fill in the information inside the DB.
-- Original Message --
I was trying my new registration form plugin on a website live (Thanks @Pieter Goosen), but there is no email sent after the user has clicked register.
The question is, is it because I use a different form that there is no email sent?
I was thinking that the default email would be sent automatically?
Do I absolutely have to setup an email inside my Plugin?
Or should I expect WordPress to do it?
-----
As Pieter mentioned in the comments, yes the emails are going through as I am using a plugin to use the SMTP and not the PHP mailer by default (Plugin named: Wp Mail Bank)
The test was made BY the Plugin (to make sure there was not configuration changes on my servers) and I also disabled my plugin and try the original email from the normal Registration form of WordPress and I got both emails without any problems.