我正在使用wp_insert_user 要插入新用户,在插入用户之前,它会检查用户是否存在,并且只注册新用户。现在,我想通知用户和管理员有关用户注册的信息。这是的代码wp_insert_user :
$user = $mail[\'header\']->fromaddress;
$email = strstr($mail[\'header\']->fromaddress, \'<\',true);
for ($j=1; $j < $total; $j++) {
$mail = $emails-> get($j);
if(email_exists($email)){
add_post_meta($post_id, \'ticket_username\', $user, True);
add_post_meta($post_id, \'ticket_email\', $email, True);
}else{
$userdata = array(
\'user_login\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'user_pass\' => \'\',
\'user_nicename\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'display_name\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'user_email\' => strstr($mail[\'header\']->fromaddress, \'<\'),
\'role\' => \'support_customer\',
);
$user_id = wp_insert_user($userdata);
if ( ! is_wp_error( $user_id ) ) {
wp_update_post( array(
\'ID\' => $post_id,
\'post_author\' => $user_id,
) );
}
}
}
下面是通知用户和管理员的代码:
if ( !function_exists( \'wp_new_user_notification\' ) ) {
function wp_new_user_notification( $user_id, $plaintext_pass = \'\' ) {
$user = new WP_User($user_id);
$user_data = get_userdata( $user_id );
$firstname = $user_data->first_name;
$user_login = stripslashes( $user_data->user_login );
// URLs
$site_url = site_url();
$ads_url = site_url( \'ads/\' );
$login_url = site_url();
// Email variables
$headers = \'From: EXAMPLE.INFO <info@example.info>\' . "rn";
$blog_name = get_option( \'blogname\' );
$admin_subject = \'New User Registration on \' . $blog_name;
$welcome_subject = \'Welcome to My site!\';
$welcome_email = stripslashes( $user_data->user_email );
$admin_email = get_option(\'admin_email\');
$admin_message =
<<<EOT
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<div class="content">
<div class="wrapper">
<p>New user registration on your blog: {$blog_name}.</p>
<p>Username: {$user_login}</p>
<p>Email: {$welcome_email}</p>
</div>
</div>
</body></html>
EOT;
$welcome_message =
<<<EOT
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<div class="content">
<div class="wrapper">
<table width="100%"><tr><td>
Hello {$firstname},<br />
To log into your account,
go <a href="{$login_url}">visit our site</a>
and use the credentials below.<br />
Your Username: {$user_login}<br />
Your Password: {$plaintext_pass}<br />
</td></tr></table>
</div>
</div>
</body></html>
EOT;
print_r($admin_email);
//die()
wp_mail( $admin_email, $admin_subject, $admin_message, $headers );
wp_mail( $welcome_email, $welcome_subject, $welcome_message, $headers );
} // End of wp_new_user_notification()
}
我猜这个代码不起作用,因为它没有发送任何电子邮件。我对这一切都很陌生,所以我希望在这里得到一些帮助。