我有下面的代碼來選擇事件,用戶和子用戶,併發送電子郵件給用戶,如果有新的事件,子用戶創建。合併內容,如果相同的變量(電子郵件)
$result_m = mysqli_query($db, $query_mail) or die(mysqli_error());
while ($re4 = mysqli_fetch_array($result_m, MYSQLI_ASSOC))
{
$ajdi = $re4["pid"];
$name1 = $re4["name"];
$surname1 = $re4["surname"];
$email1 = $re4["email"];
$mob = $re4["mob"];
$titl1 = $re4["title"];
$zip1 = $re4["zip"];
$city1 = $re4["city"];
$address1 = $re4["address"];
$insurance1 = $re4["insurance"];
$born1 = $re4["born"];
$receiver = $re4["demail"];
$content= "<p><img src='$logo'></p>";
$content.= "<p><br/>Name: $name1 $surname1, Born: $born1, Insurance: $insurance1<br/>$address1, $city1 $zip1, Tel: $mob, Email: $email1</p>";
$title= "Mail title";
$content.= "<p>Footer message</p>";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: [email protected]";
if ($receiver!= "")
{
mail($receiver, $title, $content, implode("\r\n", $headers));
}
}
這也包裹在另一個while循環得到的所有事件。 當用戶創建事件時,該用戶會收到電子郵件,但如果有更多事件,則會爲每個事件獲取電子郵件。 如何只發送一封電子郵件給所有創建的活動的用戶?
例如,當我做echo "$receiver<br>$content<br>";
我得到:
[email protected]
Some content
[email protected]
Some content2
[email protected]
Some content
[email protected]
Some content2
但我需要這樣的:
[email protected]
Some content
Some content2
[email protected]
Some content
Some content2
如何實現這一目標?謝謝
UPDATE(根據歐文穆勒回答陣列)
Array
(
[[email protected]] =>
22.07.2015., 08:30 Uhr
)
Array
(
[[email protected]] =>
23.07.2015., 08:15 Uhr
)
Array
(
[[email protected]] =>
09.09.2015., 14:45 Uhr
)
Array
(
[[email protected]] =>
03.08.2015., 14:40 Uhr
)
Array
(
[[email protected]] =>
03.08.2015., 11:40 Uhr
)
Array
(
[[email protected]] =>
03.08.2015., 14:20 Uhr
)
Array
(
[[email protected]] =>
30.07.2015., 15:40 Uhr
)
Array
(
[[email protected]] =>
24.07.2015., 14:00 Uhr
)
Array
(
[[email protected]] =>
24.07.2015., 14:00 Uhr
)
Array
(
[[email protected]] =>
30.07.2015., 15:40 Uhr
)
旁註:OP使用'MYSQL_ASSOC'應該是'MYSQLI_ASSOC'並添加「I」。你複製了相同的代碼。 –
@ Fred-ii-謝謝,我確實是盲目複製它的,因爲我專注於array-email-as-key技巧。 ;-)現在修復。 –
不客氣Erwin。 –