I made a custom registration page with validations on email, password and name are working fine. After registration an email will be sent together with an activation code which is also working. I wanted to display an error message in case if wp_mail does not send an email to users. How do i display error message if wp_mail failed?
Here is my code for sending mail:
$user_id = wp_insert_user( ); //i removed this part because its a very long code but insert user works
$code = sha1( $user_id . time() ); /*for activation code*/
$activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id ), get_permalink( get_page_by_path('register/success') )); //for server success page
//$activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id ), get_permalink(772));
$activate_url = '<a href="'.$activation_link.'">'.$activation_link.'</a>';
add_user_meta( $user_id, 'has_to_be_activated', $code, true );
//add_user_meta( $user_id, 'ja_disable_user', 2, true );
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
//modify email sender
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
$to = $email;
$from = 'noreply@test.co';
$headers = 'From: '.$from . "rn";
$subject = __($locale['email_subject']);
$msg = __($locale['user_confirm_message_1']) ." URL: ". $activate_url ." ". __($locale['user_confirm_message_2']) ." ". __($locale['email_footer']);
wp_mail( $to, $subject, $msg, $headers );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
if( is_wp_error($user_id) ) {if( is_wp_error($user_id) ) {
$err = 'Error on user creation.';
}
else {
do_action('user_register', $user_id);
$updated_date = current_time( 'mysql' );
$wpdb->insert( 'client_detail', array('client_id' => $user_id, 'updated_date' => $updated_date), array('%s', '%s') );
update_user_meta( $user_id, 'ja_disable_user', 2);
$success = 'You're successfully register';
}
Check Like this: