我正在尝试通过for循环发送多封电子邮件,所以我不必担心隐藏所有其他电子邮件,但每次我测试它时,它会一直发送数组中的最后一封电子邮件,总是错过第一封电子邮件和姓氏。
以下是每个数组元素如何读取“firstname lastname< email>”(引号只是从句子中分离出来)
以下是代码:
$to = $_POST['to'];
$from = "$sender";
$subject = $_POST['subject'];
$message = $_POST['message'];
$i = "";
if($to == "Mass email"){
$sql =("SELECT * FROM `$table5`");
$res = mysqli_query($con5, $sql) or die (mysqli_error());
$adresses = [];
while($row = mysqli_fetch_assoc($res)){
$email = $row['firstname'] . " " . $row['lastname'] . " <" . $row['email'] . ">";
$adresses[] = $email;
}
foreach($adresses as $value){
if(empty($_FILES['file'])){
$mbox = imap_open("{mail.server.com:993/novalidate-cert/imap/ssl}", "$eun", "$epw");
$sent_mass_1 = mail($value, $subject, $message, "From: $from");
if($sent_mass_1){
imap_append($mbox, "{mail.server.com:993/novalidate-cert/imap/ssl}INBOX.Sent"
, "Date: $date\r\n"
. "To: " . $value . "\r\n"
. "From: $from\r\n"
. "Subject: $subject\r\n"
. "\r\n"
. "$message\r\n"
);
}
}
}
我刚开始使用php数组,我还有很多需要学习的东西