2015-06-21 75 views
0

试图建立联系页面。我希望能够一次发送多封电子邮件。电子邮件地址已从数据库中提取。我正在管理让他们一起做。然而,要添加“密送”所有地址我需要他们在一个变量,例如$电子邮件。我似乎无法弄清楚如何做到这一点。这是我到目前为止有:做变量php中的重复区域

$username = $_POST['Username']; 
    $email = $_POST['email']; 
    $to="email goes here"; 
    $from= $_POST['email']; 
    $subject= "Raiding Team Announcement"; 
    $footer="© Copyright 2015 All Rights Reserved "; 

      $message .= '<html><body>'; 
      $message .= '<div style="width:100%; background-color:#333;">'; 
      $message .= '<h1 style="font-size:50px; color:#FFCC00; text- align:center; display:block; padding-bottom:15px; border-bottom:1px solid #AA0114; ">HellscreamsFury</h1>'; 
      $message .='<h2 style="font-size:32px;color:#f37e0e; text-align:center;">' .$_POST["Username"].' says:</h2>'; 
      $message .='<div style="margin:30px; padding:10px; border:1px solid #404040; margin-bottom:50px;">'; 
      $message .='<p style="font-size:18px; color:#ccc;">' .$_POST["message"]. '</p>'; 
      $message .= '</div>'; 
      $message .= '<div style="border-top:1px solid #AA0114;">'; 
      $message .='<p style="font-size:12px; color:#fff; text-align:center; padding: 20px 0 50px 0;">' .$footer. '</p>'; 
      $message .= '</div>'; 
      $message .= '</div>'; 
      $message .= '</body></html>'; 
      $headers .= "From: " . $from . "\r\n"; 
      $headers .= "MIME-Version: 1.0\r\n"; 
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
      if(mail($to,$subject,$message,$headers)){ 
    header("Location: ../announcments.php?aid=43"); 
} 
else{ 
header("Location: ../announcments.php?aid=44"); 
} 

这段代码在我的电子邮件拉:

<?php do { ?> 
    <?php echo $row_rs_contact_team['email']; ?> 
    <?php } while ($row_rs_contact_team = mysql_fetch_assoc($rs_contact_team)); ?> 

我需要他们在一个变量来坐 - 假设$电子邮件。我怎么做?另外,在检查user_id时,也会收到电子邮件,但有时user_id会重复 - 是否有办法一次拉取该电子邮件,而不是拉扯三次?

+0

现在,你可以;能够设置“密件抄送”?无法做出循环? –

+0

从技术上讲,我可以,但我需要从数据库中取出所有电子邮件坐在BCC,那里我想知道如何转换所有电子邮件中的一个字符串,数组或变量?所以我可以将一个变量($ emails)放入BCC – WebAmateur

+0

这很简单,就像循环和拼接。你想让我解释一下吗? –

回答

0

可以通过将它迭代到while循环并将其连接并在其附近添加逗号来完成。

$CountingQuery = "SELECT * FROM users"; 
$ExecutingCountingQuery = $Connection->query($CountingQuery); 
$Bcc = ''; // Declaring a Variable 
while($row = $ExecutingCountingQuery->fetch_array()) 
    { 
    $Bcc .=$row['email'].','; 
    } 
echo $Bcc; // Now $Bcc is your expected output 
//The output will be something like 

//[email protected],[email protected],[email protected],[email protected], 

注:

我不知道你用什么名字来存储电子邮件coloumn。所以我使用名称email作为邮件列。

此外,我已经使用*您可以根据需要替换它。