For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > January 2005 > Really Stuck!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Really Stuck!
Ben

2005-01-25, 8:55 am

Hello all,

As a beginner I have been trying to send two attachments from my HTML =
form.
Below is the code I have been using. The problem is, I seem to only be =
able
to send one or the other, when I send both, although they go through, =
the
text I want displayed tags 6110 etc, is also sent as an attachment. Any =
help
would be greatly appreciated as I have a huge headache!

<?php

$to =3D "ben@turnerlittle.com";
$from =3D $_POST['from'];
$subject =3D $_POST['subject'];
$message =3D "";
if ($t6111 !=3D "")
$message .=3D stripslashes("6111=3D$t6111\n");
if ($t6110 !=3D "")
$message .=3D stripslashes("6110=3D$t6110\n");
if ($t6100 !=3D "")
$message .=3D stripslashes("6100=3D$t6100\n");
if ($t6112 !=3D "")
$message .=3D stripslashes("6112=3D$t6112\n");
if ($t6101 !=3D "")
$message .=3D stripslashes("6101=3D$t6101\n");



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


$headers =3D "From: $from";

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

// Generate a boundary string
$semi_rand =3D md5(time());
$mime_boundary =3D "=3D=3DMultipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .=3D "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=3D\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message =3D "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=3D\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

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

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


$fileattt =3D $_FILES['fileattt']['tmp_name'];
$fileattt_type =3D $_FILES['fileattt']['type'];
$fileattt_name =3D $_FILES['fileattt']['name'];

$headers =3D "From: $from";

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

// Generate a boundary string
$semi_rand =3D md5(time());
$mime_boundary =3D "=3D=3DMultipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .=3D "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=3D\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message =3D "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=3D\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

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

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

}
// Send the message
$ok =3D @mail($to, $subject, $message, $headers);
if ($ok) {
header ("Location: http://www.tlwebsolutions.co.uk/form/");
}
?>=20
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com