Hi...
I'm trying to make it possible to send out personalized email messages to about 1000 email addresses stored in mysql database. So far i wrote the code below, and it doesn't seem to work. The email gets sent out, it has problems... first user in the database gets an email correctly, second user gets the personalized message for himself and the previous user in 1 email... third user gets his details and details of previous 2 users in 1 email too.. and so on.
Can anyone tell me why this doesn't work please?
// select all the people from database
$sql = "SELECT * FROM users";
$result = @($sql);
while ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$firstname = $row["firstname"];
$lastname = $row["lastname"];
$email = $row["email"];
$subject = "Test";
$headers .= "From: Test <xx@email.com>\n";
$headers .= "Return-Path: <xx@email.com>\n";
$message .= "Hi...\n";
$message .= "\n";
$message .= "This message goes out to..n";
$message .= "\n";
$message .= "Firstname: $firstname\n";
$message .= "Lastname: $lastname\n";
mail($email, $subject, $message, $headers);
echo "Sending mail to: $email...<br>";
}
echo "Done!";