我有以下代碼是爲向用戶發送電子郵件提醒而編寫的,但它僅向列表中的第一個用戶發送電子郵件,其餘用戶未通過電子郵件發送。該查詢在SQL中工作,以拉所有的用戶PHP中的Foreach循環只能獲得第一個實例
$users = array(mysql_fetch_array(mysql_query("SELECT DISTINCT wp_users.* FROM wp_users LEFT JOIN (SELECT lead_id, MAX(case when field_number = 7 then value end) AS email, MAX(case when field_number = 8 then value end) AS tournament_id FROM wp_rg_lead_detail GROUP BY lead_id) AS t1 ON t1.email = wp_users.user_email AND t1.tournament_id = '$tournament_id' WHERE t1.lead_id IS NULL AND id !=1")));
// Create the replacements array
$replacements = array();
foreach ($users as $user) {
$replacements[$user['user_email']] = array (
'{user_login}' => $user['user_login']
);
echo $user['user_email'] . "<br />" . $user['user_login'];
}
// Create the mail transport configuration
$transport = Swift_MailTransport::newInstance();
// Create an instance of the plugin and register it
$plugin = new Swift_Plugins_DecoratorPlugin($replacements);
$mailer = Swift_Mailer::newInstance($transport);
$mailer->registerPlugin($plugin);
// Create the message
$message = Swift_Message::newInstance();
$message->setSubject("Pure Fantasy Golf Pick Reminder for {user_login}");
$message->setBody("{user_login}, this is a reminder that you need to submit a pick for this weeks tournament " . $tournament_name . ". Please go to http://dev.purefantasygolf.com to make your pick now.");
$message->setFrom("[email protected]", "Pure Fantasy Golf");
// Send the email
foreach($users as $user) {
$message->setTo($user["user_email"], $user["user_login"]);
$mailer->send($message);
}
var_dump($ users),這是否包含你想要的? – Naruto
你的意思是你甚至沒有'print_r($ users)'來查看你是否有你所有的行? –