title: HTML/PHP mail() : Content Not Showing in Email with Attachment sent Through PHP
body: <p>The issue: Emails sent with HTML and attachment do not show content. There is no issue with the attachment. Before I attempted to send it as an HTML email, the message and attachment were fine. </p>
  
  <p>The code: I am using the following code to send emails with attachments:</p>
  
  <pre><code>    //Email to Customer or Tech
      $file = "../PDF/phptopdf/".$_GET['pdf'];
      $lgth = strlen($_GET['pdf']);
      $intsta = strpos($_GET['pdf'],'/')+1;
      $intend = $lgth - strpos($_GET['pdf'],'.');
      $intendname = $lgth - strpos($_GET['pdf'],'_');
      $filename = substr($_GET['pdf'],$intsta,-$intend);
  
      $content = file_get_contents($file);
      $content = chunk_split(base64_encode($content));
  
      // a random hash will be necessary to send mixed content
      $separator = md5(time());
  
      // carriage return type (RFC)
      $eol = "\r\n";
  
      // main header (multipart mandatory)
      $headers = "From: ".$_SESSION['userFName']." ".$_SESSION['userLName']." &lt;".$_SESSION['email']."&gt;" . $eol;
      $headers .= "MIME-Version: 1.0" . $eol;
      $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
      $headers .= "Content-Transfer-Encoding: 8bit" . $eol;
  
      // message
      $body = "--" . $separator . $eol;
      $body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;
      $body .= "Content-Transfer-Encoding: quoted-printable" . $eol;
  
      if ($_POST['sendToTech'] == '1') {
          $mailto = $_POST['techEmail'];
          $subject = 'New Work Order for '.$compName;
          $pos = strpos($_POST['techName'],' ');
          $techFName = substr($_POST['techName'],0,$pos);
          $message = "&lt;html&gt;&lt;body&gt;";
          $message .= "&lt;table style='border:1px solid #000;font-size:18px;line-height:20px;'&gt;&lt;tr&gt;&lt;td style='text-align:center;padding:10px;'&gt;&lt;img src='MY LOGO URL' /&gt;&lt;/tr&gt;&lt;/td&gt;";
          $message .= "&lt;tr&gt;&lt;td style='padding:10px;'&gt;";
          $message .= "Hello ".$techFName.", &lt;br/&gt;&lt;br/&gt;";
          $message .= "I have assigned work order #00-".$_GET['idQ']." for ".$compName." to you. &lt;br/&gt;";
          $message .= "The work is scheduled for ".date('F jS, Y \a\t g:i A',strtotime($serviceDate))." at ".$address.". &lt;br/&gt;";
          $message .= "Click on the attachment to view the work order or &lt;a href='MYURL".$_GET['pdf']."'&gt;Click Here&lt;/a&gt;. &lt;br/&gt;&lt;br/&gt;";
          $message .= "Thank you, &lt;br/&gt;";
          $message .= $_SESSION['userFName']."&lt;br/&gt;&lt;br/&gt;&lt;/tr&gt;&lt;/td&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;";
          $body .= $message . $eol;
  
          // attachment
          $body .= "--" . $separator . $eol;
          $body .= "Content-Type: application/pdf; name=\"" . $filename . "\"" . $eol;
          $body .= "Content-Transfer-Encoding: base64" . $eol;
          $body .= "Content-Disposition: attachment" . $eol;
          $body .= $content . $eol;
          $body .= "--" . $separator . "--";
          //SEND Mail
          if (mail($mailto, $subject, $body, $headers)) {
              echo "&lt;span class='message mg'&gt;Work Order #00-".$idQ." has been emailed to ".$_POST['techName']." at ".$_POST['techEmail']."&lt;/span&gt;&lt;br/&gt;";
          } else {
              $msg[] = "Error: " . $mysqli-&gt;error;
              echo "&lt;span class='message alert'&gt;An error occured while attempting to send Work Order #00-".$idQ." to ".$_POST['techEmail']."&lt;/span&gt;";
          }
      }
  </code></pre>
  
  <p>When the email arrives it looks like this:
  <a href="https://i.stack.imgur.com/DLQll.png" rel="nofollow noreferrer">Email in Gmail</a></p>
  
  <p>But, when I look into the original message I see the content that is not displayed: 
  <a href="https://i.stack.imgur.com/6GD3m.png" rel="nofollow noreferrer">Original Message View</a></p>
  
  <p>Solutions that I have attempted:</p>
  
  <ol>
  <li>Removing "This is a multi-part message in MIME format" (<a href="https://stackoverflow.com/questions/32907773/php-mail-function-html-content-not-visible-in-email">PHP mail function html content not visible in email</a>)</li>
  <li>Changing  <code>$body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;</code>  -- to <code>text/plain</code> (just to see if that would do anything...)</li>
  <li><p>Changing  <code>$headers .= "Content-Transfer-Encoding: 8bit" . $eol;</code> -- from <code>7bit</code> and <code>quoted-printable</code></p></li>
  <li><p>Removing <code>&lt;html&gt;&lt;body&gt;</code> and closing tags</p></li>
  </ol>