所以我用PHP這樣的多個用戶:PHP發送郵件從數據庫中選擇
if(isset($userID)) {
$premium = $con->prepare("
SELECT Email
FROM tblName as d
WHERE Rank = $rank and Type = $type
");
$premium->execute();
$premium->bind_result($email);
} else {
echo "There is no User ID detected, try to refresh browser.";
}
while ($premium->fetch()) {
# SUBJECT (Subscribe/Remove)
$subject = "New Resume";
# RESULT PAGE
$location = "http://www.website.com";
$sender = "[email protected]";
# MAIL BODY
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "</table>";
$message .= "</body></html>";
$cc = "[email protected]om";
$headers = "From: " . $sender . "\r\n";
$headers = "BCC: " . $cc . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['Email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to = $email;
mail($to, $subject, $message, $headers) or die ("Mail could not be sent.");
}
header("Location: http://website.com/");
die();
mysqli_close($link);
但是對於每個選定的用戶來說,這不是發送電子郵件。我可以正確使用循環嗎?我應該使用foreach
還是改進while
循環?我怎麼能在這種情況下申請arrays
?有人能以正確的方式得到我嗎?謝謝!
您通過SQL內直接嵌入變量缺少'準備statements'點 - 使用佔位符和PDO分配變量uing'bind_param'在'mysqli'或'bindParam'。最初的'headers'用'$ headers =「BCC:」的第二行覆蓋。 $ cc。 「\ r \ n」;' – RamRaider
您在代碼中有很多錯誤 – mohade
@mohade感謝您的回覆,我想聽聽任何有關如何改進代碼的建議。 – Infinity