Bluehost.com Web Hosting $6.95

Multiple Attachements on email

This is a discussion on Multiple Attachements on email within the PHP General forums, part of the PHP Programming Forums category; Hi i wonder if any one can help. I have script that that sends a email with mulitple attachments. It ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-22-2008
shawfamily318@blueyonder.co.uk
 
Posts: n/a
Default Multiple Attachements on email

Hi

i wonder if any one can help. I have script that that sends a email
with mulitple attachments. It seems to work fine as i get the email
with the attachments on. But other people i send it to only get 1
attachment????

The script is below

<?php
// Read POST request params into global vars
$name = $_POST['your_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$check1 = $_POST['check1'];
$check2 = $_POST['check2'];
$check3 = $_POST['check3'];
$check4 = $_POST['check4'];
$check5 = $_POST['check5'];
$color = $_POST['color'];
$manufacturer = $_POST['Manu'];
$findwebsite = $_POST['through'];
$comments = $_POST['comments'];

// Obtain file upload vars
$fileatt = $_FILES['pic1']['tmp_name'];
$fileatt_type = $_FILES['pic1']['type'];
$fileatt_name = $_FILES['pic1']['name'];


// Obtain file upload vars
$fileatt2 = $_FILES['pic2']['tmp_name'];
$fileatt2_type = $_FILES['pic2']['type'];
$fileatt2_name = $_FILES['pic2']['name'];


// Obtain file upload vars
$fileatt3 = $_FILES['pic3']['tmp_name'];
$fileatt3_type = $_FILES['pic3']['type'];
$fileatt3_name = $_FILES['pic3']['name'];


$headers = "From: Web@test";
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "Name : " . $name . "\n";
$message .= "Phone : " . $phone . "\n";
$message .= "Email Address : " . $email . "\n";
$message .= "Item They Require : \n" ;
$message .= $check1 . "\n";

if ( $check2 <> "" )
{
$message .= $check2 . "\n";
}

if ( $check3 <> "")
{
$message .= $check3 . "\n";
}
if ( $check4 <> "")
{
$message .= $check4 . "\n";
}

if ( $check5 <> "")
{
$message .= $check5 . "\n";
}

$message .= "Color : " . $color . "\n";
$message .= "Manufacturer : " . $manufacturer . "\n";
$message .= "Found Web Through : " . $findwebsite . "\n";
$message .= "Comments \n" . $comments . "\n";



if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);



// Add a multipart boundary above the plain message
$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";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

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

if (is_uploaded_file($fileatt2)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt2,'rb');
$data = fread($file,filesize($fileatt2));
fclose($file);



// Add a multipart boundary above the plain message
// $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";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt2_type};\n" .
" name=\"{$fileatt2_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt2_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}

if (is_uploaded_file($fileatt3)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt3,'rb');
$data = fread($file,filesize($fileatt3));
fclose($file);



// Add a multipart boundary above the plain message
//$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";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt3_type};\n" .
" name=\"{$fileatt3_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt3_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$ok = @mail("<taken addrress out for protection>", "Web Enquiry",
$message, $headers);
if ($ok) {
echo "<span class='title'>The following details have been sent<br></
span>";
echo "<p><B>Name : </B>" . $name . "</p>";
echo "<p><B>Phone Number :</B> " . $phone . "</p>";
echo "<p><B>Email Address :</B> " . $email . "</p>";
echo "<br><B>Item Required :</B> ";
echo "<br>" . $check1;

if ( $check2 <> "" )
{
echo "<BR>" . $check2;
}

if ( $check3 <> "")
{
echo "<BR>" . $check3;
}
if ( $check4 <> "")
{
echo "<BR>" . $check4;
}

if ( $check5 <> "")
{
echo "<BR>" . $check5;
}
echo "<p><B>Color :</B> " . $color . "</p>";
echo "<p><B>Manufacturer :</B> " . $manufacturer . "</p>";
echo "<p><B>Found Site Through :</B> " . $findwebsite . "</p>";
echo "<p><B>Comments :</B> " . $comments . "</p>";


} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0