Hi Im using PHP mail to send messages from a DB> However with the code below I get multiple emails from a single query. Hence if a query has 10 results, I get 10 emails. How can sort this out. Thanks
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "test";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT stimee, pango,kembo FROM layla";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$msg = "Time: " . $row["stimee"]. " - pango: " . $row["pango"]. " " . $row["kembo"] . "<br>";
$msg = wordwrap($msg,70);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Benge Man <[email protected]>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("[email protected]","Notification",$msg,$headers);
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
mailoutside of thewhileloop. Move the$headersoutside the while as well and then have the$msgconcatenate.mailoutside the loop