I have following piece of code, which inserts usernames and other details of users in the database. After inserting the usernames I want to email them using wp_mail();
. I am unable to do so. How can I do this?
$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'
)
);
I have following piece of code, which inserts usernames and other details of users in the database. After inserting the usernames I want to email them using wp_mail();
. I am unable to do so. How can I do this?
$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'
)
);
Share
Improve this question
edited Dec 14, 2019 at 17:17
butlerblog
5,1213 gold badges28 silver badges44 bronze badges
asked Jul 20, 2018 at 14:07
MineshMinesh
3173 silver badges15 bronze badges
2 Answers
Reset to default 0Assuming that $member_details->user_login
is already a user in the wp_users
table, then you could use the following to get their email address:
$user = get_user_by( $member_details->user_login, 'login' );
From there, you have the user's email address and can use wp_mail()
to email them:
$subject = "My email subject";
$message = "My message body...";
wp_mail( $user->user_email, $subject, $message );
Let us see what code you are trying. Assuming that the hook you have bound that function to is firing, you would insert this into your function, assuming you want to email the author.
wp_mail($to = $post_author, $subject = 'This is the subject', $message = 'This is the message');
https://developer.wordpress/reference/functions/wp_mail/
Edit:
$user = get_userdatabylogin($member_details->user_login);
$user_id = $user->ID;
wp_mail($user_id, 'This is the subject', 'This is the message');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744903907a4600138.html
评论列表(0条)