Page 1 of 1
Instructions to upload and send file via email needed.
Posted: Wed Sep 16, 2009 6:51 pm
by WithHisStripes
Heya - so I'm working on this site:
http://pro-ad-co.theportlandco.com and I have to allow the user to upload a file and then, on submit, send that file via email to my clients specified address. I can't, for the life of me, find a clear tutorial on this. Can someone help? Thanks!
Re: Instructions to upload and send file via email needed.
Posted: Wed Sep 16, 2009 7:10 pm
by Mirge
You didn't specify which part you're having trouble with, so I'll assume you can't figure any of it out.
File Uploading:
http://www.php.net/manual/en/features.file-upload.php
Emailing Attachments:
http://www.webcheatsheet.com/PHP/send_e ... chment.php
Happy coding.
Re: Instructions to upload and send file via email needed.
Posted: Wed Sep 16, 2009 7:43 pm
by WithHisStripes
Well I do know how to run a file uploader, but I've never successfully paired that with a script to send email. Before I got your reply I was successful in creating this:
http://pro-ad-co.theportlandco.com/sendfile.php
Which upon visiting sends the specified file. But as soon as I take that exact code and place it in here, it sends cryptographic text instead of the image file.
Code: Select all
$company_name = $_REQUEST['company-name'];
$attention = $_REQUEST['attention'];
$address = $_REQUEST['address'];
$city = $_REQUEST['city'];
$phone = $_REQUEST['phone'];
$fax = $_REQUEST['fax'];
$email = $_REQUEST['email'];
/* SCREEN PRINTED ITEM DETAILS */
$decal_cling_length = $_REQUEST['decal-cling-length'];
$decal_cling_width = $_REQUEST['decal-cling-width'];
$decal_cling_material = $_REQUEST['decal-cling-material'];
$decal_cling_material_other = $_REQUEST['decal-cling-material-other'];
$decal_cling_adhesive = $_REQUEST['decal-cling-adhesive'];
$decal_cling_quantity = $_REQUEST['decal-cling-quantity'];
$decal_cling_quantity_other = $_REQUEST['decal-cling-quantity-other'];
$decal_cling_number_of_colors = $_REQUEST['decal-cling-number-of-colors'];
$decal_cling_number_of_colors_other = $_REQUEST['decal-cling-number-of-colors-other'];
$sign_length = $_REQUEST['sign-length'];
$sign_width = $_REQUEST['sign-width'];
$sign_material = $_REQUEST['sign-material'];
$sign_material_other = $_REQUEST['sign-material-other'];
$sign_quantity = $_REQUEST['sign-quantity'];
$sign_quantity_other = $_REQUEST['sign-quantity-other'];
$sign_number_of_colors = $_REQUEST['sign-number-of-colors'];
$sign_number_of_colors_other = $_REQUEST['sign-number-of-colors-other'];
$hang_tag_length = $_REQUEST['hang-tag-length'];
$hang_tag_width = $_REQUEST['hang-tag-width'];
$hang_tag_material = $_REQUEST['hang-tag-material'];
$hang_tag_material_other = $_REQUEST['hang-tag-material-other'];
$hang_tag_quantity = $_REQUEST['hang-tag-quantity'];
$hang_tag_quantity_other = $_REQUEST['hang-tag-quantity-other'];
$hang_tag_number_of_colors = $_REQUEST['hang-tag-number-of-colors'];
$hang_tag_number_of_colors_other = $_REQUEST['hang-tag-number-of-colors-other'];
/* FINISHING */
$clear_coat_uv_protection = $_REQUEST['clear-coat-uv-protection'];
$square_rectangle_cut = $_REQUEST['square-rectangle-cut'];
$die_cut_special_shape = $_REQUEST['die-cut-special-shape'];
$back_score = $_REQUEST['back-score'];
$face_score = $_REQUEST['face-score'];
$rounded_corners = $_REQUEST['rounded-corners'];
$holes = $_REQUEST['holes'];
$lamination_1_mil_polyester = $_REQUEST['lamination-1-mil-polyester'];
$serial_number = $_REQUEST['serial-number'];
$application_tape = $_REQUEST['application-tape'];
$lamination_2_mil_polyester = $_REQUEST['lamination-2-mil-polyester'];
$special_finishing = $_REQUEST['special-finishing'];
/* DIGITAL GRAPHICS */
$full_color = "full-color";
$number_of_spot_colors = "number-of-spot-colors";
$special_colors = "special-colors";
$digital_graphics_length = "digital-graphics-length";
$digital_graphics_width = "digital-graphics-width";
$digital_graphics_flexible = "digital-graphics-flexible";
$digital_graphics_flexible_other = "digital-graphics-flexible-other";
$digital_graphics_rigid = "digital-graphics-rigid";
$digital_graphics_rigid_other = "digital-graphics-rigid-other";
$digital_graphics_material = "digital-graphics-material";
$digital_graphics_material_other = "digital-graphics-material-other";
$digital_graphics_quantity = "digital-graphics-quantity";
/* ADDITIONAL NOTES */
$additional_notes = $_REQUEST['additional-notes'];
$key = substr($_SESSION['key'],0,5);
$number = $_REQUEST['number'];
if ($number != $key) {
echo "
<style type='text/css'>
.red {
color: red;
}
</style>
<p class='red'>Whoops, you didn't enter the correct answer. <a href='#' onClick='parent.history.back(); return false;'><< Go back</a></p>
";
exit;
}
$fileatt = "../the-portland-website-design-company/images/logo.png"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$email_from = "noreply@theportlandco.com"; // Who the email is from
$email_subject = "It worked!"; // The Subject of the email
$email_txt = "This is the message."; // Message that the email has in it
$email_to = "spencerhill@theportlandco.com"; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$data = chunk_split(base64_encode($data));
$message = "
Customer Name: <span style='color: red;'>" . $company_name . "</span>
Attention: " . $attention . "
Address: " . $address . "
City: " . $city . "
Phone: " . $phone . "
Fax: " . $fax . "
Email: " . $email . "
Notes: " . $additional_notes . "
Decal Cling Length: " . $decal_cling_length . "
Decal Cling Width: " . $decal_cling_width . "
Decal Cling Material: " . $decal_cling_material . "
Decal Cling Material Other: " . $decal_cling_material_other . "
Decal Cling Adhesive: " . $decal_cling_adhesive . "
Decal Cling Quantity: " . implode(', ', $decal_cling_quantity) . "
Decal Cling Quantity Other: " . $decal_cling_quantity_other . "
Decal Cling Number of Colors: " . $decal_cling_number_of_colors . "
Decal Cling Number of Colors Other: " . $decal_cling_number_of_colors_other . "
Sign Length: " . $sign_length . "
Sign Width: " . $sign_width . "
Sign Material: " . $sign_material . "
Sign Material Other: " . $sign_material_other . "
Sign Quantity: " . implode(', ', $sign_quantity) . "
Sign Quantity Other: " . $sign_quantity_other . "
Sign Number of Colors: " . $sign_number_of_colors . "
Sign Number of Colors Other: " . $sign_number_of_colors_other . "
Hang Tag Length: " . $hang_tag_length . "
Hang Tag Width: " . $hang_tag_width . "
Hang Tag Material: " . $hang_tag_material . "
Hang Tag Material Other: " . $hang_tag_material_other . "
Hang Tag Quantity: " . implode(', ', $hang_tag_quantity) . "
Hang Tag Quantity Other: " . $hang_tag_quantity_other . "
Hang Tag Number of Colors: " . $hang_tag_number_of_colors . "
Hang Tag Number of Colors Other: " . $hang_tag_number_of_colors_other . "
Clear Coat UV Proection: " . $clear_coat_uv_protection . "
Square Rectangle Cut: " . $square_rectangle_cut . "
Die Cut Special Shape: " . $die_cut_special_shape . "
Back Score: " . $back_score . "
Holes: " . $holes . "
Polyester 1 Mil: " . $lamination_1_mil_polyester . "
Polyester 2 Mil: " . $lamination_2_mil_polyester . "
--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
/*clif@proadco.com*/
$ok = @mail($email_to, $email_subject, $message, $headers);
if($ok) {
echo "<h1>The file was successfully sent!</h1>";
}
Re: Instructions to upload and send file via email needed.
Posted: Wed Sep 16, 2009 8:05 pm
by WithHisStripes
Here's a simplified version:
Code: Select all
$key = substr($_SESSION['key'],0,5);
$number = $_REQUEST['number'];
if ($number != $key) {
echo "
<style type='text/css'>
.red {
color: red;
}
</style>
<p class='red'>Whoops, you didn't enter the correct answer. <a href='#' onClick='parent.history.back(); return false;'><< Go back</a></p>
";
exit;
}
$fileatt = "../the-portland-website-design-company/images/logo.png"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$file = fopen($fileatt,'rb');
$data = fread(fopen($fileatt,'rb'),filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "From: noreply@proadco.com";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt}\"\n" . "Content-Transfer-Encoding: base64\n\n" . chunk_split(base64_encode($data)) . "\n\n" . "--{$mime_boundary}--\n" . "
Customer Name: " . $company_name . "
Attention: " . $attention . "
Address: " . $address . "
City: " . $city . "
Phone: " . $phone . "
Fax: " . $fax . "
Email: " . $email . "
Notes: " . $additional_notes . "
Decal Cling Length: " . $decal_cling_length . "
Decal Cling Width: " . $decal_cling_width . "
Decal Cling Material: " . $decal_cling_material . "
Decal Cling Material Other: " . $decal_cling_material_other . "
Decal Cling Adhesive: " . $decal_cling_adhesive . "
Decal Cling Quantity: " . implode(', ', $decal_cling_quantity) . "
Decal Cling Quantity Other: " . $decal_cling_quantity_other . "
Decal Cling Number of Colors: " . $decal_cling_number_of_colors . "
Decal Cling Number of Colors Other: " . $decal_cling_number_of_colors_other . "
Sign Length: " . $sign_length . "
Sign Width: " . $sign_width . "
Sign Material: " . $sign_material . "
Sign Material Other: " . $sign_material_other . "
Sign Quantity: " . implode(', ', $sign_quantity) . "
Sign Quantity Other: " . $sign_quantity_other . "
Sign Number of Colors: " . $sign_number_of_colors . "
Sign Number of Colors Other: " . $sign_number_of_colors_other . "
Hang Tag Length: " . $hang_tag_length . "
Hang Tag Width: " . $hang_tag_width . "
Hang Tag Material: " . $hang_tag_material . "
Hang Tag Material Other: " . $hang_tag_material_other . "
Hang Tag Quantity: " . implode(', ', $hang_tag_quantity) . "
Hang Tag Quantity Other: " . $hang_tag_quantity_other . "
Hang Tag Number of Colors: " . $hang_tag_number_of_colors . "
Hang Tag Number of Colors Other: " . $hang_tag_number_of_colors_other . "
Clear Coat UV Proection: " . $clear_coat_uv_protection . "
Square Rectangle Cut: " . $square_rectangle_cut . "
Die Cut Special Shape: " . $die_cut_special_shape . "
Back Score: " . $back_score . "
Holes: " . $holes . "
Polyester 1 Mil: " . $lamination_1_mil_polyester . "
Polyester 2 Mil: " . $lamination_2_mil_polyester;
$ok = @mail('spencerhill@theportlandco.com', "You've recieved a request.", $message, $headers);
if($ok) {
echo "<h1>The file was successfully sent!</h1>";
}
What's happening now though is it seems to ignore the other content. So it's choosing either to send the file, or send the text with cryptographic text representing my uploaded file.