FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Email Attaching a file already uploaded
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
icon14.gif  solution! [message #31785 is a reply to message #31717] Thu, 18 May 2006 02:22 Go to previous message
PhilVaz is currently offline  PhilVaz   United States
Messages: 2
Registered: May 2006
Karma:
Junior Member
All righty, here's the solution Very Happy

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

[Message index]
 
Read Message icon5.gif
Read Message icon14.gif
Previous Topic: Shopping Carts
Next Topic: Logging users into the forum from a separate site
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 01:27:06 GMT 2024

Total time taken to generate the page: 0.04814 seconds