title: Retrieve data from database in email
body: <p>I am using sendmail to send the emails in php. The problem is, I would like to retrieve  details in database within the mail. How can I do that ? Here's my code. </p>
  
  <pre><code>&lt;?php
  // set database server access variables: 
  $host = "localhost"; 
  $user = "root"; 
  $pass = ""; 
  $db = "master_inventory";
  
  // open connection 
  $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
  
  // select database 
  mysql_select_db($db) or die ("Unable to select database!"); 
  
  // create query 
  $query = "SELECT * FROM desktop"; 
  
  // execute query 
  $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
  
  // see if any rows were returned 
  if (mysql_num_rows($result) &gt; 0) { 
  
  $to       = 'nazasdei@domain.com';
  $subject  = 'warranty licensed expired';
  $message  = 'The Following Your Product Expired
            Product Code:.$row[Desk_PC_Name]';
  $headers  =  'From: miloe@gmail.com' . "\r\n" .
               'Reply-To: miloe@gmail.com' . "\r\n" .
               'MIME-Version: 1.0' . "\r\n" .
               'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();
  }       
  if(mail($to, $subject, $message, $headers))
  echo "Email sent";
  else
  echo "Email sending failed";
  
  ?&gt;
  </code></pre>