php - 使用 php,mysql 从数据库中的电子邮件列表发送电子邮件
问题描述
我正在尝试向存储在数据库中的所有成员电子邮件 ID 发送电子邮件。这是代码
<?php
$sql = mysqli_query($con,"select email from email_list where email");
//$recipients = array();
while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) {
$recipients[]= $row['email'];
}
$to = $recipients;
$repEmail = 'abc@gmail.com';
$subject = "$title";
$body = "$description";
$headers = 'From: xyz <'.$repEmail.'>'. "\r\n";
$headers .= 'Reply-To: abc@gmail.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
if (mail($to, $subject, $body, $headers)){
echo "<script>alert('Email sent')</script>";
}
else {
echo "<script>alert('Email failed')</script>";
}
?>
在上面的代码中,电子邮件发送给 1 个人。
解决方案
您的 $to 应该是 $to = "address@one.com, address@two.com, address@three.com"
所以添加
$recipients = array(
"youremailaddress@yourdomain.com",
// more emails here
);
$email_to = implode(',', $recipients); // your email address
将 $email_to 添加到您的 $to。
推荐阅读
- javascript - React 循环问题 - TypeError:无法读取未定义的属性“id”
- swagger - 招摇给出结构错误
- ios - 运行 add2app ios 时使用本地颤振引擎
- jmeter - 运行带有 nohup 的 JMeter 脚本,给出“没有这样的文件或目录”
- kubernetes - 是否可以为通过 OKE Kubernetes Ingress 部署的 OCI 负载均衡器定义资源标签?
- ios - 分段错误:11(在项目“X”的目标“X iOS”中)[Xcode 11.4/11.4.1]
- c++ - 如何在 C++ 中有效地将集合格式化为字符串?
- nuxt.js - 如何在 Phusion Passenger 上部署 nuxt SSR 应用
- apache-spark - 如何忽略我们从 CSV 读取输入数据的 Spark Dataframe 中的双引号?
- mysql - 如何查询一位客户及其推荐客户并显示他们的所有交易