我有以下代码,它在数据库中插入用户名和其他用户详细信息。插入用户名后,我想使用wp_mail();
. 我不能这样做。我该怎么做?
$member_details->user_login = array_map( \'sanitize_text_field\', $_POST[\'user_login\'] );
$member_details->user_role = array_map( \'sanitize_text_field\', $_POST[\'user_role\'] );
$member_details->status = array_map( \'sanitize_text_field\', $_POST[\'status\'] );
$member_details_encode = wp_json_encode( $member_details );
global $wpdb;
$member_result = $wpdb->insert( \'wpxa_project_members\',
array(
\'project_id\' => $_SESSION[\'project_id\'],
\'author_id\' => $post_author,
\'member_details\' => $member_details_encode
),
array(
\'%d\',
\'%d\',
\'%s\'
)
);
SO网友:butlerblog
假设$member_details->user_login
已是中的用户wp_users
表,则可以使用以下内容获取他们的电子邮件地址:
$user = get_user_by( $member_details->user_login, \'login\' );
从那里,您可以获得用户的电子邮件地址,并可以使用
wp_mail()
发送电子邮件给他们:
$subject = "My email subject";
$message = "My message body...";
wp_mail( $user->user_email, $subject, $message );
SO网友:LearntoExcel
让我们看看您正在尝试什么代码。假设您将该函数绑定到的挂钩正在启动,您可以将其插入到您的函数中,假设您想向作者发送电子邮件。
wp_mail($to = $post_author, $subject = \'This is the subject\', $message = \'This is the message\');
https://developer.wordpress.org/reference/functions/wp_mail/
编辑:
$user = get_userdatabylogin($member_details->user_login);
$user_id = $user->ID;
wp_mail($user_id, \'This is the subject\', \'This is the message\');