I am trying to email values from a MySQL database to a user when prompted. I cannot seem to pass the information off to the body of the email message with the correct values. Here is a code sample:
mysql_connect ("host","name","pass") or die (mysql_error());
mysql_select_db ("db_name");
$sql = mysql_query("select * from table_name where id = '$id'");
//$id is previously defined as the users id
while ($row = mysql_fetch_array($sql)){
$title = $row["title"];
}
$email = 'user@email.com'
$subject = "Titles";
$body = "Title: " . $title;
if (mail($email, $subject, $body)) {
echo("<p>successfully sent. "</p>");
} else {
echo("<p>delivery failed...</p>");
}
I have tried running an array in the while loop to get the title values to display, but again I cannot seem to get these values to carry over to the email message.
This is assuming that each user has multiple titles being sent to them. Ideally, the final email message would be something like:
Title: Title1
Title: Title2
Title: Title3
Title: Title4
Title: Title5
and continue on for however many titles are in the array. Thanks for any assistance.
1 Answer