发送多封电子邮件,不同主题,不同邮件

时间:2015-10-28 11:09:33

标签: php arrays email foreach implode

我一直在试图理解这一点,而且事实证明我无法弄清楚这一点,我对你来说已经很新了。

我自己有三个阵列,我内爆(',$#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)

2 个答案:

答案 0 :(得分:0)

这是你想要达到的目标吗?

 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 :(得分:0)

  

STOP

     

你不需要内爆,你是对的

要做的步骤

  1. 在这种情况下获取数组大小3;)&lt; - for you
  2. 在阵列上使用for-each
  3. 发送邮件
  4. 现在确实很容易

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

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

相关问题