2015-06-21 74 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作爲郵件列。

此外,我已經使用*您可以根據需要替換它。