Mysql Data into Email Message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrsjrs
    New Member
    • Sep 2006
    • 24

    Mysql Data into Email Message

    <?
    $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("SE LECT * FROM users") or die(mysql_error ());
    $row = mysql_fetch_arr ay( $result );
    echo "Name: ".$row['first_name'];
    $to = "abc@xyz.co m";
    $subject = "Test mail";
    $message = "Test if message includes $row['first_name']";
    $from = "ddd@hhh.co m";
    $headers = "From: $from";
    if (mail($to,$subj ect,$message,$h eaders))
    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.
  • brid
    New Member
    • Oct 2006
    • 13

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

    Have a nice day!

    Comment

    Working...