sanguinious Posted December 12, 2007 Share Posted December 12, 2007 I am trying to create an email that has an attachment, .doc, and contains text in the body of the email. I can get it to create an attachment and email it. And create an email with body text with a .txt file attached. But I cannot seem to create an email with a .doc attached and have body text. This code creates an email with a txt file attached and with body text. function sendmsg($to, $subject, $msgtext, $from, $file, $type) { $fp = fopen($file,"rb"); $fcontent = fread($fp ,filesize($file)); fclose($fp); $content = $fcontent; $sep = strtoupper(md5(uniqid(time()))); $name = basename($file); $header = "From: $from\nReply-To: $from\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed; boundary=$sep\n"; $body .= "--$sep\n\n"; $body .= "$msgtext\n"; $body .= "--$sep\n\n"; $body .= "$content\n"; $body .= "--$sep--"; if (mail($to, $subject, $body, $header)) { return true; } else { return false; } } sendmsg('[email protected]', 'whats up?', 'this is message', '[email protected]', 'file.txt', 'text/plain'); But when I change the function call to: sendmsg('[email protected]', 'whats up?', 'this is message', '[email protected]', 'file.doc', 'application/msword'); I get an email with body content, but a txt file attached called AT289247.txt I have tried the following to: function sendmsg($to, $subject, $msgtext, $from, $file, $type) { $fp = fopen($file,"rb"); $fcontent = fread($fp ,filesize($file)); fclose($fp); $content = $fcontent; $sep = strtoupper(md5(uniqid(time()))); $name = basename($file); $header = "From: $from\nReply-To: $from\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed; boundary=$sep\n"; $body .= "--$sep\n"; $body .= "Content-Type: text/plain\n"; $body .= "Content-Transfer-Encoding: 8bit\n\n"; $body .= "$msgtext\n"; $body .= "--$sep\n"; $body .= "Content-Type: $type; name=\"$file\"\n"; $body .= "Content-Transfer-Encoding: base64\n"; $body .= "Content-Disposition: attachment; filename=\"$file\"\n"; $body .= "$content\n"; $body .= "--$sep--"; if (mail($to, $subject, $body, $header)) { return true; } else { return false; } } Which works, as I get an email with body text and a .doc attached but the .doc is empty. Any input would be appreciated. Thanks, Angus. Link to comment https://forums.phpfreaks.com/topic/81335-email-doc-and-email-contents/ Share on other sites More sharing options...
farkewie Posted December 12, 2007 Share Posted December 12, 2007 Im not 100% on this but you may need to use COM for word docs, i know you need to if you want to create them but reading im not so sure Link to comment https://forums.phpfreaks.com/topic/81335-email-doc-and-email-contents/#findComment-412797 Share on other sites More sharing options...
sanguinious Posted December 12, 2007 Author Share Posted December 12, 2007 ah ok, will have a look into that. thanks for the response, angus. Link to comment https://forums.phpfreaks.com/topic/81335-email-doc-and-email-contents/#findComment-412839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.