Connecting Tech Pros Worldwide Forums | Help | Site Map

Mysql Data into Email Message

Newbie
 
Join Date: Sep 2006
Posts: 24
#1: Oct 17 '06
<?
$link = mysql_connect("server", "database", "password") or die("Could not connect : " . mysql_error());
$DB = "database";
$table = "users";
mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error());
$result = mysql_query("SELECT * FROM users") or die(mysql_error());
$row = mysql_fetch_array( $result );
echo "Name: ".$row['first_name'];
$to = "abc@xyz.com";
$subject = "Test mail";
$message = "Test if message includes $row['first_name']";
$from = "ddd@hhh.com";
$headers = "From: $from";
if (mail($to,$subject,$message,$headers))
echo "Mail Sent";
else
echo "Mail message failed";
?>
.....................................
In the above program I am trying to use php and mysql to extract " first_name " from the database and then place the contents of " first_name " into the email message.
The above program will NOT work if - $row['firstname'] - is included in the $message line, but works just fine without it.
I have tried many variations in $message but none have worked.
I have extracted the value of " first_name " correctly from the database, since it prints out correctly in the " echo " line.
Can anyone tell me the proper programming protocol to correctly place the name extracted from the mysql database into the email message ?
Thanks.

Newbie
 
Join Date: Oct 2006
Location: Beside my computer :)
Posts: 13
#2: Oct 18 '06

re: Mysql Data into Email Message


worked code:
$message = "Test if message includes ".$row['first_name'];

Have a nice day!
Reply