How can I retrieve rows from database then use a mail()
function to then email that list in my php file.
The query that I am using which this works:
$sql = "SELECT * FROM leads WHERE date_stamp BETWEEN '$currentdate' - INTERVAL 7 DAY AND '$currentdate'";`
But the problem I am having is listing out all the data to then email, I am only getting the one result from database, but not all the rows. I know its the way my loop is setup, that is what I am needing help with.
Below is the full code minus the database connect.
$to = 'email@email.com';
// email subject
$subject = 'Email leads beginning '.$newdate." through ".$currentdate;
// Construct email body
$result = mysqli_query($conn, $sql);
$recipients = array();
while($rows = mysqli_fetch_assoc($result)) {
foreach ($result as $row) {
$content = $row['first_name']." ".$row['last_name']."<br>";
}
};
$body_message = $content;
// email headers
$headers = 'From: ' . $email_from . "\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $body_message, $headers);