<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>
此代码用于从数据库中选择电子邮件地址并向其发送电子邮件。我的代码有什么问题,我无法收到任何电子邮件,帮助将不胜感激。谢谢!
答案 0 :(得分:3)
答案 1 :(得分:3)
这一行
while (mysql_fetch_array($result_query_email)
您需要将mysql_fetch_array()
的返回值分配给变量才能在while()
循环中使用它以及缺少结束)
while ($emaildata = mysql_fetch_array($result_query_email)) {
{
$email_user = $emaildata['email'];
//.....rest of code
也
Please, don't use mysql_*
functions in new code。它们不再维护,弃用过程已经开始,请参阅red box。请改为了解prepared statements,并使用PDO或MySQLi; this article会帮助您确定哪个。如果您选择PDO here is a good tutorial。
修改强>
此外,您似乎尝试将变量用作关联数组,您需要使用mysql_fetch_assoc()
代替mysql_fetch_array()
来执行此操作
答案 2 :(得分:0)
如果您没有在源代码中提供,请在您的服务器PHP.ini中设置正确的SMTP服务器地址。