1

以下のスクリプトを調整して、2 つのことを実行できるようにします。

  1. 複数のアドレスに電子メールを送信します (現在、1 つの電子メール アドレスに電子メールが送信されている場合にのみ機能します。
  2. 「宛先」フィールドには、同じ通知を受け取った他のすべての人が表示されるべきではありません。そのため、各メールは個別に感じられる必要があります。

コード:

         //Query to get emails
         //$share_to comes from a drop down selection of users.  
         //it could be 1 person or multiple people.
         //The way its stored in the field is this way user1,user2,user3,user4 or if one person then just user1.  

         $sql = "SELECT email_address from accounts 
         WHERE person_id='$share_to'";
         $result = mysql_query($sql);

         $query = mysql_query($sql) or die 
         ("Error: ".mysql_error());

         if ($result == "")
         {
         echo "";
         }
         echo "";


         $rows = mysql_num_rows($result); 


         if($rows == 0)
         {
         print("");

         }
         elseif($rows > 0)
         {
         while($row = mysql_fetch_array($query))

         {

         $email = htmlspecialchars($row['email_address']);


         print("");
         }

         }


         $headers = "MIME-Version: 1.0\r\n";
         $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
         $headers .= "From: $usermail\r\n";
         $headers .= "BCC: $email\r\n";
         $to = "support@domain.com"; //the mail in the "TO", visible to all. 
         there has to be 1.
         $subject = "$fullname Asked you something";
         $message = "<html><body>";
         $message .= "Hi!, <br><br>$fullname asked you something.<br><br>";
         $message .= "<a href=www.domain.com/login.php>Click here to login.</a><br><br>";
         $message .= "Please reply to this email if you have any questions.<br><br>Thanks,    
         <br><br>Abe<br>";
         $message .= "<img src=www.domain.com/images/logohop.png /><br><br>";

         $message .= "</body></html>";
         mail($to, "Subject: $subject",
         $message, "$headers" );
         echo "";
4

3 に答える 3

1

これらのいずれかを使用すると、複数のユーザーに電子メールを送信できます

$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";

また

$headers .= 'Cc: birthdayarchive@example.com,birthdayarchive2@example.com ' . "\r\n";

ヘルプについては、 http://php.net/manual/en/function.mail.phpを参照してください。

$headers .= 'BCc: birthdayarchive@example.com,birthdayarchive2@example.com ' . "\r\n";連絡先から他のユーザーを非表示にするために使用します

于 2012-04-26T19:36:46.407 に答える
0
//Query to get emails
         //$share_to comes from a drop down selection 
         of users.  it could be 1 person or multiple 
         people.The way its stored in the field is 
         this way user1,user2,user3,user4 
         or if one person then just user1.  

         $sql = "SELECT email_address from accounts 
         WHERE person_id='$share_to'";
         $result = mysql_query($sql);

         $query = mysql_query($sql) or die 
         ("Error: ".mysql_error());

         if ($result == "")
         {
         echo "";
         }
         echo "";


         $rows = mysql_num_rows($result); 


         if($rows == 0)
         {
         print("");

         }
         elseif($rows > 0)
         {
         $email='';
         while($row = mysql_fetch_array($query))

         {

         $email. = htmlspecialchars($row['email_address']).',';


         print("");
         }

         }


         $headers = "MIME-Version: 1.0\r\n";
         $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
         $headers .= "From: $usermail\r\n";
         $headers .= "BCC: ".rtrim($email,",")."\r\n";
         $to = "support@domain.com"; //the mail in the "TO", visible to all. 
         there has to be 1.
         $subject = "$fullname Asked you something";
         $message = "<html><body>";
         $message .= "Hi!, <br><br>$fullname asked you something.<br><br>";
         $message .= "<a href=www.domain.com/login.php>Click here to login.</a><br><br>";
         $message .= "Please reply to this email if you have any questions.<br><br>Thanks,    
         <br><br>Abe<br>";
         $message .= "<img src=www.domain.com/images/logohop.png /><br><br>";

         $message .= "</body></html>";
         mail($to, "Subject: $subject",
         $message, "$headers" );
         echo "";
于 2012-04-26T19:56:24.383 に答える
-1

受信者に完全なリストを見せたくない場合は、複数の電子メールを各受信者に 1 つずつ送信することができます - Dagon が上で述べたように、メール コードをループ内に移動するだけです - または BCC フィールドを使用できます。

1 つの電子メールを複数の受信者に送信するには、カンマ区切りのアドレス リストを - に追加する必要があります。

$emails = array();
while($row = mysql_fetch_array($query)) {
    $emails[] = htmlspecialchars($row['email_address']);
}

その後:

$headers .= "BCC: " . implode(",", $emails) . "\r\n";

やるべきです。

于 2012-04-26T19:45:37.300 に答える