admin管理员组文章数量:1206598
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=".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.
本文标签: plugin developmentUsing wpmail to send email
版权声明:本文标题:plugin development - Using wp_mail to send email? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738723989a2108920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论