I have certain instances where I want to send emails to both user and admin accordingly using wp_mail
.
The first instance is when a new user is created.
The following code is used to create users:
//Get all users and if user exists get username and email or else create new user as support customer.
$user = strstr($mail['header']->fromaddress, '<',true);
$email = $mail['header']->fromaddress;
for ($j=1; $j < $total; $j++) {
$mail = $emails-> get($j);
if(email_exists($email)){
add_post_meta($post_id, 'username', $email, True);
add_post_meta($post_id, 'email', $user, 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( $user_id ) :
$get_userdata = get_userdata( $user_id );
$get_user_email = $userdata['user_email'];
wp_mail( $userdata['user_email'],'test sub', 'Email' .$userdata['user_email']. 'is created','');
endif;
if ( ! is_wp_error( $user_id ) ) {
wp_update_post( array(
'ID' => $post_id,
'post_author' => $user_id,
) );
}
}
}
After the user is created both the admin and user should get an email. I also created a template to be sent:
<section id="email-template">
<div class="container">
<div class="row">
<div class="wrapper">
<div class="logo">
<img src="./img/logo.png" alt="LOGO">
</div>
<div class="text-1">
<p>Hi <b>Jeon Jungkook</b>,<br>
A client you are in charge of just posted a new reply to his ticket <a href="#123">"Spring"</a>.
</p>
</div>
<div class="message">
<h2>Message:</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Iure non
exercitationem maxime nostrum eaque eos quaerat libero explicabo id?
Temporibus omnis qui dolorum provident debitis voluptatum veritatis
ipsa necessitatibus mollitia quaerat consequuntur.</p>
</div>
<div class="ticket-button">
<a href="https://codethemes.co/wp-admin/post.php?post=33177&action=edit" class="btn">View Ticket </a>
</div>
<div class="message">
<p class="after">If you are responsible for the ticket, please go ahead and do the needful.</p>
</div>
<hr>
<footer>
<div class="down">
<p class="up">Updates by FAQPress </p>
<div class="vertical"></div>
<p><a href="#">Unsubscribe.</a></p>
</div>
</footer>
</div>
</div>
</div>
</section>
Now I want to use this template and sent an email. Similarly the second instance is for comments and so on. If I can get help with this instance I think I can do rest by myself.
Registration notification
. Other than that, what exactly aboutwp_mail
is unclear? What have you tried so far?wp_mail
to send emails to multiple users such as both admin and user at the same time. I have seen the functionality ofwp_mail
and also I am new to all this so I want to use it to send it to multiple users.wp_mail
? Are you saying you know how to usewp_mail
to send an email but want to know how to do a specific thing? You need to write a specific question that can be factually and fully answered, but this isn't phrased as a question