Jump to content


Photo

Email Attachment Sending


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 26 July 2006 - 03:35 PM

Hi

OK so all the things in the world I can do with mail() I just cant figure out how to attach a file to the email sent.

Can Anyone  tell me the Header information etc that is needed for this. And does the file need uploading before its sent??? Tutorials? I mean good ones not crap ones!

cheers
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 July 2006 - 04:11 PM

It involves modifying the headers. Try to Google for "PHP MAIL ATTACHMENTS"

Or try PHP-Mailer or SWIFT - ready made PHP mailers
~ D Kuang

#3 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 26 July 2006 - 04:25 PM

This works for me...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   $to = "recipient email";
   $subject = "Your subject";
   $email = $_POST['requiredemail'];
   $address = $_POST['requiredaddress'];
   $zip = $_POST['requiredzip'];
   
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
   
   $tmp_name = $_FILES['filename']['tmp_name'];
   $type = $_FILES['filename']['type'];
   $name = $_FILES['filename']['name'];
   $size = $_FILES['filename']['size'];
   
   $message = "
   From: $email\n
   Address: $address\n
   Zip: $zip\n
   
   if (file_exists($tmp_name)){
   if(is_uploaded_file($tmp_name)){
   $file = fopen($tmp_name,'rb');
   $data = fread($file,filesize($tmp_name));
   fclose($file);
   
   $data = chunk_split(base64_encode($data));
}

   $headers = "From: $email\r\n" .
   "MIME-Version: 1.0\r\n" .
   "Content-Type: multipart/mixed;\r\n" .
   " boundary=\"{$mime_boundary}\"";

   $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";

   $message .= "--{$mime_boundary}\n" .
         "Content-Type: {$type};\n" .
         " name=\"{$name}\"\n" .
         //"Content-Disposition: attachment;\n" .
         //" filename=\"{$fileatt_name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

if (@mail($to, $subject, $message, $headers))
echo "Thank you your file has been sent";
else
echo "An error has occured. Please fill out the form and try again";
   }
} else {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1">
<input name="filename" type="file" size="30"/>
<input name="submit" type="submit" value="Submit"/>
</form><?php } ?>
</body>
</html>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users