|
solution! [message #31785 is a reply to message #31717] |
Thu, 18 May 2006 02:22 |
PhilVaz
Messages: 2 Registered: May 2006
Karma: 0
|
Junior Member |
|
|
All righty, here's the solution
To attach a Word doc that is already online
<?php
$subject="subject line";
$from = "email(at)something(dot)com";
$type = "application/msword";
$name = "file.doc";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$message = "$toname, your doc is attached.\n\nThank you for visiting the site.";
// open and read the file as binary
$file = fopen($name,'rb');
$data = fread($file,filesize($name));
fclose($file);
// encode and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
// message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// message body
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// insert a boundary to indicate start of the attachment
// specify content type, file name, and attachment
// then add file content and set another boundary
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// send the message
if (@mail($toemail, $subject, $message, $headers)) echo "$toname, your Email with attachment was sent.<br><br>Thank you for visiting the site.";
else echo "Sorry, failed to send Email, please try again in a few minutes.";
?>
Phil P
[Updated on: Thu, 18 May 2006 02:24] Report message to a moderator
|
|
|