title: Send pdf attachment to emails in mysql database using php
body: <p>Code:</p>
  
  <pre><code>   &lt;?php
     $servername = "localhost";
      $username = "username";
     $password = "****";
     // Create connection
     $conn = new mysqli($servername, $username, $password);
     // Check connection
       if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
      }
  $sql = "SELECT email, name FROM MyGuests";
  $result = $conn-&gt;query($sql);
  if ($result-&gt;num_rows &gt; 0) {
  // output data of each row
  while($row = $result-&gt;fetch_assoc()) {
  
  $conn-&gt;close();
  
      ?&gt;
  
  
  &lt;table width="348" border="0"&gt;
   &lt;tr&gt;
     &lt;td width="88"&gt;Name&lt;/td&gt;
  &lt;td width="98"&gt;Email&lt;/td&gt;
  &lt;td width="148"&gt;Select All
  
      &lt;label&gt;
        &lt;input type="checkbox" name="checkbox" id="checkbox"&gt;
      &lt;/label&gt;    &lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
  &lt;?php {?&gt;&lt;td&gt;&lt;?php echo $row["name"];?&gt;
      }
  &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row["email"];?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;label&gt;
    &lt;input type="checkbox" name="checkbox" id="checkbox"&gt;
  &lt;/label&gt;&lt;/td&gt;&lt;?php } else {
  echo "0 results";
  }?&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&amp;nbsp;&lt;/td&gt;
   &lt;td&gt;&lt;label&gt;
    &lt;input type="submit" name="button" id="button" value="Send"&gt;
   &lt;/label&gt;&lt;/td&gt;
      &lt;/tr&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>I want to send email with attached pdf files to the email users listed in the table. I have a generated pdf files in a folder called "slips" which has the emails as the filename for example every filename bears the name of the emails in the database eg. smith@test.com in the email column and a pdf file named smith@test.com.pdf</p>
  
  <p>What is the best php code to use for such problem. </p>