title: How to send data in email using HTML table & php
body: <p>I'm trying to send data from database in the form of a HTML table when user click submit button. I'm able to receive the email but only table received. It doesn't seem database data. I want to email a table with data in database. Here is my code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  require '../Mailer/PHPMailerAutoload.php';
  
  $mail = new PHPMailer;  
  $mail-&gt;isSMTP();     
  //$mail-&gt;SMTPSecure = 'tls';
  //$mail-&gt;SMTPAuth = true;
  $mail-&gt;Host = '';
  $mail-&gt;Port = ;  
  $mail-&gt;Username = '';
  $mail-&gt;Password = '';
  $mail-&gt;setFrom('');
  $mail-&gt;addAddress('');
  $mail-&gt;isHTML(true);
  $mail-&gt;Subject = 'Student data';
  $body = '&lt;html&gt;
          &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
           &lt;style&gt;
      table {
      border-collapse: collapse;
      width: 100%;
  }
  
  th, td {
    border: 1px solid #ddd;
      text-align: left;
      padding: 8px;
      color:black
  }
  
  tr:nth-child(even){background-color: #f2f2f2}
  
  th {
      background-color: #4CAF50;
      color: white;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
    
   &lt;?php
        $username = "root";
        $password = "";
        $host = "localhost";
  
        $connector = mysqli_connect("$host,$username,$password");
            or die("Unable to connect");
          echo "Connections are made successfully::";
        $selected = mysqli_select_db("school"," $connector");
          or die("Unable to connect");
  
        //execute the SQL query and return records
        $result = mysqli_query("SELECT*FROM student ");
        ?&gt;
         &lt;table&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th&gt;id&lt;/th&gt;
            &lt;th&gt;name&lt;/th&gt;
            &lt;th&gt;age&lt;/th&gt;
            &lt;th&gt;class&lt;/th&gt;
            &lt;th&gt;address&lt;/th&gt;
            &lt;th&gt;comment&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
          &lt;?php
            while( $row = mysql_fetch_assoc( $result ) ){?&gt;
            &lt;tr&gt;
                
                
                &lt;td&gt;&lt;?php echo $row["id"] ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["name"]?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["age"] ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["class"] ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["address"] ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["comment"] ?&gt;&lt;/td&gt; 
  
              &lt;/tr&gt;
         &lt;?php   }
          ?&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
       &lt;?php mysql_close($connector); ?&gt;
      
  
   
  
  &lt;/body&gt;
  &lt;/html&gt; ';
  
  $mail-&gt;Body = $body;
  
  
  //send the message, check for errors
  if (!$mail-&gt;send()) {
      echo "ERROR: " . $mail-&gt;ErrorInfo;
  } else {
      echo "SUCCESS";
  }</code></pre>
  </div>
  </div>
  </p>