我制作了一个自定义注册页面,其中包含有关电子邮件,密码和名称的验证工作正常。注册后,电子邮件将与激活码一起发送,激活码也可以使用。如果wp_mail没有向用户发送电子邮件,我想显示错误消息。如果wp_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 . "\r\n";
$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';
}
答案 0 :(得分:0)
像这样检查:
if (wp_mail(...) )
{
// we're good to go
}
else {
echo "error"
}