Current location: Hot Scripts Forums » Programming Languages » PHP » E-Mail with attachment

E-Mail with attachment

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-02-09, 07:01 AM
GazzaMataz GazzaMataz is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
E-Mail with attachment

Quote:
<?php
//Set up email and attachment details
$to = "gazzamataz@compuserve.com";
$subject = "Evolution Office Supplies - Recruitment Form";

// Store the file information to variables for easier access
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
$job = $_POST["job"];
$salutation = $_POST["salutation"];
$fromename = $_POST["fromname"];
$address = $_POST["address"];
$phone = $_POST["phone"];
$fromemail = $_POST["fromemail"];
$about = $_POST["about"];

//Form contents
$message = "You have a job enquiry: $name \n
Job Required: $job \n
Salutation: $salutation \n
From: $fromename \n
Address: $address \n
Telephone: $phone \n
E-mail: $fromemail \n
About yourself: $about";

//Read in the attachment
if (file_exists($tmp_name)){
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name, 'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
//Encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

//Add the MIME content
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $fromemail\r\n".
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
"boundary=\"{$mime_boundary}\"";

//Message header
$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 boundary to indicate we're starting the attachment
// Specify the content type, file name and disposition as an attachment.
// Then add the file content and set another boundary to indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
//Send the e-mail
mail($to, $subject, $message, $headers);


?>
Can anyone help me with this script? When I use it without an attachment it works, as soon as I add an attachment it still gets sent but there is nothing in the e-mail.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail authentication sujata_ghosh Perl 9 06-24-08 01:45 AM
Attachement help needed sujata_ghosh Perl 18 06-22-07 02:00 PM
Php Mail form - Adding an attachment vivabensmith Script Requests 4 11-14-06 04:21 AM
Mail with attachment sharad PHP 3 08-03-06 06:35 PM
mail ( ) + attachment rsuresh PHP 1 06-16-04 10:26 AM


All times are GMT -5. The time now is 08:32 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.