Shemo
July 27th, 2008, 23:23
Ok, so my buddy wrote this script with his little php knowledge...it's working 95%....what I'm trying to do is allow my site visitors to be able to upload photos to us via the form and the browse function..once they click submit on the form, I'm trying to get it to package up the form with the questions answered and the photo attached in the email...he got the processor to attach a file, but it's a .txt with nothing inside of it..with his limited php knowledge, he wasn't able to get the code to process the actual image..so here is the form in the .html code and the .php code...please, if you figure it out, post what was wrong so I can let my buddy know!!!
Thanks again,
Shemo
**Email addresses have been removed, but they're in the file**
<!-- Upload Form -->
<div style="margin-top: 15px; margin-right: auto; margin-bottom: 15px; margin-left: auto; color: #FFFFFF; text-align: center;">
<form enctype="multipart/form-data name="upload_photos" action="email.php" method="POST">
<p>Name: <br />
<input type="text" name="name" /></p>
<p>E-Mail: <br />
<input type="text" name="email" /></p>
<p>State: <br />
<input type="text" name="state" /><p>
<p>Car Make: <br />
<input type="text" name="make" /></p>
<p>Car Model: <br />
<input type="text" name="model" /></p>
<p>How did you hear about us: <br />
<input type="text" name="aboutus" /></p>
<p>Upload: <br />
<input name="fileatt" type="file" />
<input type="hidden" name="hidden" value="1" /><br /><br />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</div>
<?php
$to = '';
$name = $_POST['name'];
$email = $_POST['email'];
$subject = 'ugly cars';
$state = $_POST["state"];
$car_make = $_POST["make"];
$car_model = $_POST["model"];
$about_us = $_POST["aboutus"];
$comments = "Name:" . $name .
"\nState: " . $state .
"\nCar Make: " . $car_make .
"\nCar Model: " . $car_model .
"\nHow did you hear about us:" . $about_us ;
$fileatt= $_POST["fileatt"];
$hidden = $_POST['hidden'];
$from = $email;
$form_data = "<p>This email is from <span class=\"bold\">$name</span> \n\n ";
$form_data .= "<p>$comments</p>";
$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" .
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \n" .
"<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" .
"<head> \n" .
" <meta http-equiv=\"content-type\" content= \n" .
" \"text/html; charset=iso-8859-1\" /> \n" .
"<style type=\"text/css\"> \n" .
"body { font-size: 9pt; font-family: verdana, sans-serif; color: #000; background:#fff; } \n" .
".bold { font-weight: bold; } \n" .
"</style> \n" .
"</head> \n" .
"<body>$form_data \n" .
"</body> \n" .
"</html> \n\n";
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// 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}\"";
// Add a multipart boundary above the html message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; 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));
//We now have everything we need to write the portion of the message that contains the file attachment. Here's the code:
// 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";
//That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail:
// Send the message
mail($to, $subject, $message, $headers);
print ('<h1 id="content_h1"><a name="text"> Thank you </a></h1> ');
// This is the end of the insert
?>
Thanks again,
Shemo
**Email addresses have been removed, but they're in the file**
<!-- Upload Form -->
<div style="margin-top: 15px; margin-right: auto; margin-bottom: 15px; margin-left: auto; color: #FFFFFF; text-align: center;">
<form enctype="multipart/form-data name="upload_photos" action="email.php" method="POST">
<p>Name: <br />
<input type="text" name="name" /></p>
<p>E-Mail: <br />
<input type="text" name="email" /></p>
<p>State: <br />
<input type="text" name="state" /><p>
<p>Car Make: <br />
<input type="text" name="make" /></p>
<p>Car Model: <br />
<input type="text" name="model" /></p>
<p>How did you hear about us: <br />
<input type="text" name="aboutus" /></p>
<p>Upload: <br />
<input name="fileatt" type="file" />
<input type="hidden" name="hidden" value="1" /><br /><br />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</div>
<?php
$to = '';
$name = $_POST['name'];
$email = $_POST['email'];
$subject = 'ugly cars';
$state = $_POST["state"];
$car_make = $_POST["make"];
$car_model = $_POST["model"];
$about_us = $_POST["aboutus"];
$comments = "Name:" . $name .
"\nState: " . $state .
"\nCar Make: " . $car_make .
"\nCar Model: " . $car_model .
"\nHow did you hear about us:" . $about_us ;
$fileatt= $_POST["fileatt"];
$hidden = $_POST['hidden'];
$from = $email;
$form_data = "<p>This email is from <span class=\"bold\">$name</span> \n\n ";
$form_data .= "<p>$comments</p>";
$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" .
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \n" .
"<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" .
"<head> \n" .
" <meta http-equiv=\"content-type\" content= \n" .
" \"text/html; charset=iso-8859-1\" /> \n" .
"<style type=\"text/css\"> \n" .
"body { font-size: 9pt; font-family: verdana, sans-serif; color: #000; background:#fff; } \n" .
".bold { font-weight: bold; } \n" .
"</style> \n" .
"</head> \n" .
"<body>$form_data \n" .
"</body> \n" .
"</html> \n\n";
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// 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}\"";
// Add a multipart boundary above the html message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; 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));
//We now have everything we need to write the portion of the message that contains the file attachment. Here's the code:
// 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";
//That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail:
// Send the message
mail($to, $subject, $message, $headers);
print ('<h1 id="content_h1"><a name="text"> Thank you </a></h1> ');
// This is the end of the insert
?>