title: php mail function with pdf attachment and html message
body: <p>I have an issue to send email with PDF attachment and message content is html format. Please checkout my below code. HTML email works fine. but the issue is in pdf attachment. </p>
  
  <pre><code>&lt;?php
  $random_hash = md5(date('r', time()));
  $headers = "From: ".$from."\r\nReply-To: ".$from;
  $headers .= "\r\nContent-Type: text/html; boundary=\"PHP-mixed-".$random_hash."\"";
  
  foreach($summaryArray as $summaryArrayValue)
  {
    $file  = 'pdf_directory/'.$summaryArrayValue['result_filename'].'.pdf';
    $fileName = $summaryArrayValue['result_filename'];
  
    $attachment = chunk_split(base64_encode(file_get_contents($file)));
    $message.=&lt;&lt;&lt;EOD
    Content-Type: application/octet-stream; name="{$fileName}" // tried with both application/octet-stream and application/pdf
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment
  
    {$attachment}
    --PHP-mixed-{$random_hash}--
  
  EOD;
  }
  
  $mail_sent = mail( $to, $subject, $message, $headers );
  echo $mail_sent ? "Mail sent" : "Mail failed";
  ?&gt;
  </code></pre>