what I want to do is to read a document that could be a pdf, doc or docx file. And add its contents with same styling in an email body. Currently, I am sending the document as an attachment but I want it to be sent in my email body. I tried searching for a generic solution that I could use for all these different types of documents, but couldn't find something related to my scenario. Most of the solutions were related to sending file as an attachment. Your help is appreciated. Thanks.
Here's the code I'm using to send the document as an attachment.
$file = 'path/to/my/file.pdf';
$content = file_get_contents( $file);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$file_name = basename($file);
// header
$header = "From: Support <info@support.com>\r\n";
$header .= "Reply-To: info@support.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
// message & attachment
$nmessage = "--".$uid."\r\n";
$nmessage .= "Content-type:text/html; charset=\"iso-8859-1\"\r\n";
$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$nmessage .= $message."\r\n\r\n";
$nmessage .= "--".$uid."\r\n";
$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$nmessage .= "Content-Transfer-Encoding: base64\r\n";
$nmessage .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$nmessage .= $content."\r\n\r\n";
$nmessage .= "--".$uid."--";
if (mail($mailto, $subject, $nmessage, $header))
return true; // Or do something here
else
return false;