我正在向我的訂閱者發送電子郵件,並且所有電子郵件地址都被插入到MYSQl的表中。但有了它,我想發送一些位於同一數據庫的其他表中的文章。請幫幫我。在「$ name」中它只提取1行(我想獲取所有給定ID的數據)。無法使用PHP發送電子郵件時從MYSQL獲取數據
<?php if(isset($_POST['send'])){
$servername = "localhost";
$username = "username ";
$password = "password ";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM table1 where id in (1, 3, 2, 4)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$name = $row["title"];
}}else {}
$conn->close();
}
?>
<?php if(isset($_POST['send'])){
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT email, subid FROM table2";
$result = $conn->query($sql);
if ($result->num_rows > 0) {while($row = $result->fetch_assoc()){
$subid = $row["subid"];
$email_to = $row["email"];
$subject = "Newsletter | OnlineDealsIndia";
$header = "From: OnlineDealsIndia <[email protected]>\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
$message = '<h3>Todays Top Deals!</h3><hr>
<li>' .$name. '</li>
<a href="http://www.onlinedealsindia.in/newsletter/unsubscribe/?subid=' .$subid. '">Click Here</a> To Unsubscribe
';
mail($email_to,$subject,$message,$header);
}}else {}
$conn->close();
}
?>
在「$ name」中,它應該獲取上面提供的id的所有行。
所有的答案將不勝感激。謝謝!
在一個循環中,您要提取'$ name',然後一遍一遍將它設置爲同一個地方。你不想把它添加到數組嗎? – tadman
它不能是「$ name」應該獲取所有4行並顯示。 –
'$ name = $ value'不會神奇地累積列表。 '$ name [] = $ value'將被添加到數組中。 – tadman