Jump to content

Email - .doc and email contents


sanguinious

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.