bunglebrown
New Member
- Messages
- 157
- Reaction score
- 0
- Points
- 0
Below is a script I'm using to retrieve a record from a mySQL database and then use it to send a message to.
I'm having some trouble however with putting the retrieved table entry into email part of the code.
Does anyone have any knowledge on what I'm doing wrong it would be great to hear from you } thanks
I'm having some trouble however with putting the retrieved table entry into email part of the code.
PHP:
<?php
//Change these
$db = 'my_database';
$user = 'my_user';
$password = 'my_password';
if(!mysql_connect('localhost', $user, $password)) {
exit(mysql_error());
}
if(!mysql_select_db($db)) exit(mysql_error());
// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM `my_table`") or die(mysql_error());
// Loop to get multiple results
while($row = mysql_fetch_array($result)){
echo "Name: ".$row['name'];
echo "Email: ".$row['email'];
}
?>
<?php
$from = "my_email";
$subject = "my_subject";
//Begin HTML Email Message
$message = "my_message";
echo ' ';
//end of message
$headers = "From: $from\r\n";
$headers = "Content-type: text/html\r\n";
$to = "$row['email']";
mail($to, $subject, $message, $headers);
exit();
?>
Does anyone have any knowledge on what I'm doing wrong it would be great to hear from you } thanks