I am storing PHP variables in DB like

Dear $name,
You are now member of TL, and your address is $address, $city.

If I echo variables they are showing as it is.. The variables have values and I want to send there values into an email.. How this can be done.. ?

<?PHP


      $link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later");
mysql_select_db($d,$link);
$query = "SELECT * FROM emails WHERE name = ".$_POST['name'].""; 
 $result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result, MYSQL_BOTH)){
$email = $row['email'];
$name = $row['name'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
}



$to      = $email;
$subject = "HELLO AND WELCOME";
$message = "hello $name , \n\n your address is $address , $city , $state";
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

Try this code.

$name = "vibha";	
echo str_replace('$name',$name,$description); // $description is database value
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.