0

是的,我是编码的初学者。

所以我要做的是首先我得到用户想要接收电子邮件的电子邮件地址(来自 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 mail 功能发送电子邮件,对于一个电子邮件地址,我可以简单地做

$ToEmail = "$iAmReceiver;
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

所以在多个电子邮件地址发送邮件直接取决于我如何存储多个电子邮件地址??......像数组一样的东西?

4

2 回答 2

2

我猜这样的事情应该有效

while ($grabit = mysql_fetch_array($query)) {
    $receivers[] = $grabit['email'];
}

$ToEmail = implode("," , $receivers);

也请考虑升级到 mysqli_* 或 pdo。mysql_* 已弃用。

于 2012-10-10T16:11:08.233 回答
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");
于 2012-10-10T16:11:10.283 回答