<html>
<body>
<?php
include 'index.php';
include '../db.php';
$query_email = "SELECT email FROM email_addresses";
$result_query_email = mysqli_query($query_email)
or die(mysqli_error());
while ($row = mysqli_fetch_array()($result_query_email)) {
//$email_user = $row[10];
$email_user = $row['email'];
$data = date("Y.m.d");
$subject = "Good news";
$message = ("Hello!");
$sentemail = mail($email_user, $subject, $message,
"From: abc <xyz.com>\nX-Mailer: PHP/" . phpversion());
}
if($sentemail)
{
print("Email has been sent successfully.<br>");
}
else
{
print("There was a problem while sending email.<br>");
}
?>
</body>
</html>
This code is to select email addresses from the database and to send them an email. what is wrong with my code, i can’t get any email, Help will be appreciated. Thanks!
This line here
you need to assign the return value of
mysql_fetch_array()to a variable to be able to use it in thewhile()loop as well as the missing closing)for instance
also
Please, don’t use
mysql_*functions in new code. They are no longer maintained and the deprecation process has begun, see the red box. Learn about prepared statements instead, and use PDO or MySQLi; this article will help you decide which. If you choose PDO, here is a good tutorial.EDIT
Also it seems like you are trying to use the variable as a associative array you need to use
mysql_fetch_assoc()instead ofmysql_fetch_array()to do that