是的,我是编码的初学者。
所以我要做的是首先获得用户想要收到电子邮件的电子邮件地址(来自db)
就像
一样$query = mysql_query("Select * FROM receivers WHERE id=$id")
or die(mysql_error());
while ($grabit = mysql_fetch_array($query)) {
$iAmReceiver = $grabit['email'];
}
因此,如果用户只有一封电子邮件只会存储在$iAmReceiver
中,但如果用户有多个用于接收电子邮件的电子邮件地址会怎样?
接下来,我使用php邮件功能发送电子邮件,我只需要一个电子邮件地址
$ToEmail = "$iAmReceiver;
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
因此,直接在多个电子邮件地址发送邮件取决于我如何存储多个电子邮件地址?? .....像数组一样?
答案 0 :(得分:2)
我猜这样的事情应该起作用
while ($grabit = mysql_fetch_array($query)) {
$receivers[] = $grabit['email'];
}
$ToEmail = implode("," , $receivers);
另外请考虑向上移动mysqli_ *或pdo。不推荐使用mysql_ *。
答案 1 :(得分:1)
您可以像这样创建逗号分隔的电子邮件:
while ($grabit = mysql_fetch_array($query)) {
$iAmReceiver .= $grabit['email'].',';
}
$iAmReceiver = rtrim($iAmReceiver,',')
$ToEmail = "$iAmReceiver";
//You can pass comma separated email id as first argument of email if you want to send mail on multiple emails
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");