对于我的会员网站,所有帐户都在后端创建。创建新用户后,我希望他们收到一封电子邮件以设置其密码。但是,默认的Wordpress电子邮件需要进行一些更改,因此我创建了以下代码以禁用默认电子邮件并创建自定义电子邮件:
function vc_mailtrap($phpmailer){
if( strpos($phpmailer->Subject, 'Logingegevens') ){
$phpmailer->ClearAllRecipients();
}
}
add_action('phpmailer_init', 'vc_mailtrap');
function custom_registration_email_alert( $user_id ) {
$user = new WP_User( (int) $user_id );
$user_login = $user->user_login;
$user_email = $user->user_email;
$adt_rp_key = get_password_reset_key( $user );
$rp_link = '<a href="' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '">' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '</a>';
$subject = 'Welcome!';
$message = '<h3>Welcome!</h3>';
$message .= '<p>You can set a password using the link below: </p>';
$message .= '<p>'.$rp_link.'</p>';
wp_mail( $user_email, $subject, $message );
}
add_action('user_register', 'custom_registration_email_alert', 10, 1 );
电子邮件工作正常,但是重置密码链接无效。它在电子邮件中添加了一个密钥,但是当用户单击它时,它总是表示该密钥无效。
该如何解决?谢谢!