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

E-Mail with attachment

Reply
  #1  
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.
Reply With Quote
  #2  
Old 11-02-09, 07:05 AM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,537
Thanks: 5
Thanked 20 Times in 18 Posts
Don't bother with this. Try PHPMailer instead.

Worx International Inc.
Reply With Quote
  #3  
Old 11-03-09, 01:05 PM
GazzaMataz GazzaMataz is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Took one look at PHP Mailer and my head nearly blew up…

I am very much a rookie with PHP and this script is one that I have adapted with my limited knowledge. Surely there is only one tinky winky thing wrong with it?
Reply With Quote
  #4  
Old 11-03-09, 01:27 PM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,537
Thanks: 5
Thanked 20 Times in 18 Posts
Take a look at this example:
Worx International Inc.

For get the rest of the code.
Reply With Quote
  #5  
Old 11-03-09, 01:48 PM
GazzaMataz GazzaMataz is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
OK Nico, thanks for your help I will try and get my head around it…
Reply With Quote
Reply

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

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:58 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2 (Unregistered)