[英]How to send email to all Wordpress users
我正在嘗試向所有用戶發送有關自定義事件的電子郵件。 為此,我編寫了以下代碼,但無法正常工作。 我究竟做錯了什么?
//send mail to all users
$result= $wpdb->get_var( $wpdb->prepare("SELECT user_email FROM $table_users"));
foreach($result as $email) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers.= "From:mysite<info@mysite.com>\r\n";
$message = "<b>Dear! user</b>,<br/><br/> A new share is available to purchase
for amount $".$sellamt."<br>this is an automated mail.pls don't reply to this mail. ";
$send=mail($email,"mysite:New share Available to Purchase!",$message,$headers);
}
header('Location: /offer_csuccess');
exit();
獲取所有用戶函數get_users();
$all_users = get_users();
foreach ($all_users as $user) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers.= "From:mysite<info@mysite.com>\r\n";
$message = "<b>Dear! user</b>,<br/><br/> A new share is available to purchase
for amount $".$sellamt."<br>this is an automated mail.pls don't reply to this mail. ";
$send=mail($user->user_email,"mysite:New share Available to Purchase!",$message,$headers);
}
exit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.