Reputation: 3626
I have a loop that enters each non-empty text field into a database:
foreach ($guests as $guest) {
if ($guest !== "") {
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$guest', '$night', '$date') ") or die(mysql_error());
}
}
I'd like to also print each of these names into an email, which I presume somehow containing the output within the $message variable in mail(). How is this best achieved?
On a side note, changing from by editing $headers is proving very temperamental. What is the proper way of doing this?
Upvotes: 1
Views: 1448
Reputation: 40512
For example:
$names = array();
foreach ($guests as $guest) {
if ($guest !== "") {
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$guest', '$night', '$date')") or die(mysql_error());
$names[] = $guest;
}
}
$message = "Guests: ".implode(", ", $names).". ";
I hope you're sure that $guest, $night, $date
variables are already passed through mysql_real_escape_string
function.
Upvotes: 5