Answer the question
In order to leave comments, you need to log in
How to send an email to a registered user (explanation)?
Hello! It is necessary to send a welcome letter to each registering user, in principle, everything is clear:
an example from offsite:
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
if ( isset( $_POST['first_name'] ) )
update_user_meta($user_id, 'first_name', $_POST['first_name']);
}
<?php
function send_welcome_email_to_new_user($user_id) {
$user = get_userdata($user_id);
$user_email = $user->user_email;
// for simplicity, lets assume that user has typed their first and last name when they sign up
$user_full_name = $user->user_firstname . $user->user_lastname;
// Now we are ready to build our welcome email
$to = $user_email;
$subject = "Hi " . $user_full_name . ", welcome to our site!";
$body = '
<h1>Dear ' . $user_full_name . ',</h1></br>
<p>Thank you for joining our site. Your account is now active.</p>
<p>Please go ahead and navigate around your account.</p>
<p>Let me know if you have further questions, I am here to help.</p>
<p>Enjoy the rest of your day!</p>
<p>Kind Regards,</p>
<p>poanchen</p>
';
$headers = array('Content-Type: text/html; charset=UTF-8');
if (wp_mail($to, $subject, $body, $headers)) {
error_log("email has been successfully sent to user whose email is " . $user_email);
}else{
error_log("email failed to sent to user whose email is " . $user_email);
}
}
add_action('user_register', 'send_welcome_email_to_new_user');
?>
add_action('user_register', 'send_welcome_email_to_new_user (111)');
или
add_action('user_register', 'send_welcome_email_to_new_user(getCurrentUser())');
Answer the question
In order to leave comments, you need to log in
Hello. First of all, I want to note that you need to see how the function worksadd_action()
The function send_welcome_email_to_new_user()
to get the user's id automatically, see user_register
And as for the interesting material, alas, I can't tell you anything, since this is not my forte. Nuachitsya can be as follows. Download any html theme. And try to create a topic. And all the functionality of the theme is implemented by plugins.
I hope I helped you :) if anything, please contact
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question