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('me@here.com', 'whats up?', 'this is message', 'nothing@here.com', 'file.txt', 'text/plain');

 

But when I change the function call to:

sendmsg('me@here.com', 'whats up?', 'this is message', 'nothing@here.com', '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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.