发送多封单独的电子邮件,不同的主题,不同的信息


Sending multiple, individual emails, different subject, different message

我一直在努力解决这个问题,但事实证明我不可能弄清楚,正如你所知,我对PHP还很陌生。

我有三个数组,我内爆了它们(','$array),我正试图使用一个数组中的电子邮件地址、另一个数组的名称作为主题、以及另一个阵列的名称作为消息来发送电子邮件。这能做到吗?

我自己也用下面的代码尝试过,但发送的电子邮件与其他电子邮件共享相同的信息。

我想我需要做一个foreach()来遍历这三个数组,但不太确定怎么做。有什么技巧吗?

$to      = implode(',',$name_email_pair);
$message = implode(',',$match);
$subject = implode(',',$inorder);
$headers  = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";    
$headers .= 'From: example@example.com' . "'r'n" .
'Reply-To: example@example.com' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//header("Location: thankyou.php");  
echo "<br>WORKS"; 
?>
Array (Size=3) //$name_email_pair
'Joe' => String 'Example1@Example.Com' (Length=20)
'Dave' => String 'Example2@Example.Com' (Length=20)
'Ben' => String 'Example3@Example.Com' (Length=20)
Array (Size=3) //$inorder
0 => String 'Joe' (Length=3)
1 => String 'Dave' (Length=4)
2 => String 'Ben' (Length=3)
Array (Size=3) //$match
0 => String 'Ben' (Length=3)
1 => String 'Joe' (Length=3)
2 => String 'Dave' (Length=4)

这就是您想要实现的目标吗?

 for($i=0;$i<count($name_email_pair);$i++)
    {
        $to      = $name_email_pair[$i];
        $message = $match[$i];
        $subject = $inorder[$i];
        $headers  = 'MIME-Version: 1.0' . "'r'n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";    
        $headers .= 'From: example@example.com' . "'r'n" .
        'Reply-To: example@example.com' . "'r'n" .
        'X-Mailer: PHP/' . phpversion();
        mail($to, $subject, $message, $headers);
    }
    //header("Location: thankyou.php");  
    echo "<br>WORKS"; 

如果没有,那么向我们展示他们排列的内容,这样我就可以编辑答案。

停止

你不需要崩溃,你正朝着正确的方向前进

的步骤

  1. 在这种情况下,获取数组大小3;)<--为你
  2. 用于阵列上的每个
  3. 发送邮件

现在对你来说确实很容易

foreach($mailing_credentials as $key=>$val){
// Mailing codes e.g. subject, cc, bcc etc
// Send Individual Mails
}

我从来没有粗鲁的意思,这只是我表达的有趣方式:)快乐编码!