Guest ConciergeCity Posted November 4, 2009 Report Share Posted November 4, 2009 I am trying to use a form so clients can send me pictures off my site and i cant seem to get the file to open in my email. form.php enctype="multipart/form-data"> Filename: upload_file.php= process script $fileatt = ""; // $fileatt_type = "application/octet-stream"; // $fileatt_name = ""; // $email_from = ""; // $email_subject = ""; // $email_txt = "Hello"; // $email_to = "my_email@domain.com"; // $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}\""; $email_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" . $email_message . "\n\n"; $data = chunk_split(base64_encode($data)); $email_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"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "The file was successfully sent!"; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } Quote Link to comment Share on other sites More sharing options...
falkencreative Posted November 4, 2009 Report Share Posted November 4, 2009 A couple questions... Are you trying to embed the attachment within the email content itself? Just trying to attach a specific file to the message that gets sent? I'd suggest starting here, and comparing your code to their example of an HTML email with attachment: http://www.webcheatsheet.com/php/send_email_text_html_attachment.php Quote Link to comment Share on other sites More sharing options...
cornetofreak Posted November 25, 2009 Report Share Posted November 25, 2009 theres a script called opencart.... and in there libary they have a PHP5 class for sending emails and its not built into the open cart system.. meaning you can just take the file and use it in other scripts that has attachment support Quote Link to comment Share on other sites More sharing options...
grucker Posted November 25, 2009 Report Share Posted November 25, 2009 I too am attempting to produce a form that sends an attachment, with little success. It finds the attachment and attaches the attachment but doesn't send the attachment. Anyone have a script I can peruse to get this problem resolved. Kindest regards, Grucker Quote Link to comment Share on other sites More sharing options...
falkencreative Posted November 25, 2009 Report Share Posted November 25, 2009 I too am attempting to produce a form that sends an attachment, with little success. It finds the attachment and attaches the attachment but doesn't send the attachment. Anyone have a script I can peruse to get this problem resolved. Kindest regards, Grucker The page I linked to a couple posts up on this topic has examples (I've adapted them to my needs before, so I know they work): http://www.webcheatsheet.com/php/send_email_text_html_attachment.php Quote Link to comment Share on other sites More sharing options...
cornetofreak Posted November 25, 2009 Report Share Posted November 25, 2009 (edited) Heres my version you can use Key-Features: Simple OOP Plain-Text OR Html Formatted Use both Plain-Text and Html to help with unsupported clients Able to add attachments of any sort Based on PHP-Mail Multiple Recipients in one batch Built for "Php Newbies" Available on PhpClasses for download Some Usage Smaples Simple Plain text <?php //Include the emailer class include 'Emailer.class.php'; //Load the Emailer class into a variable $Emailer = new Emailer; //Setup where and where from the message is being sent. $Emailer->set_to("some_email@some_domain.tld"); $Emailer->set_from("admin@localhost"); $Emailer->set_sender("me@domain.com"); //Afdd some message stuff $Emailer->set_subject("This is a plain-text email"); $Emailer->set_text("Hello World!"); $Emailer->send(); ?> HTML formatted with <?php //Include the emailer class include 'Emailer.class.php'; //Load the Emailer class into a variable $Emailer = new Emailer; //Setup where and where from the message is being sent. $Emailer->set_to("some_email@some_domain.tld"); $Emailer->set_from("admin@localhost"); $Emailer->set_sender("me@domain.com"); //Add some message stuff $Emailer->set_subject("This is a html formatted email"); /*Set the text if the end-user does not have the correct software to view html*/ $Emailer->set_text("Hello World! (Non html version)"); $Emailer->set_html("Hello World! (html Version)"); //html will show if supported otherwise they will be sent a nice plain-text version $Emailer->send(); ?> HTML Formatted with Attachments <?php //Include the emailer class include 'Emailer.class.php'; //Load the Emailer class into a variable $Emailer = new Emailer; //Setup where and where from the message is being sent. $Emailer->set_to("some_email@some_domain.tld"); $Emailer->set_from("admin@localhost"); $Emailer->set_sender("me@domain.com"); //Afdd some message percifics $Emailer->set_subject("This is a html formatted email with files"); /*Set the text if the end-user does not have the correct software to view html*/ $Emailer->set_html("Here's your files"); //Add some files $Emailer->add_attachments( array( "test/account_details.txt", "test/your_avater.png", "test/some_sample_source.php", "test/some_random.ext" /*Add as many as you wish but try not overload the message size by sending 100MB download lol*/ ) ); $Emailer->send(); ?> Edited November 29, 2009 by cornetofreak Quote Link to comment Share on other sites More sharing options...
grucker Posted November 30, 2009 Report Share Posted November 30, 2009 I would like to thank everyone for their advice. Every thing is working perfectly and as many attachments as anyone could want. One problem solved. Regards David Quote Link to comment Share on other sites More sharing options...
PicnicTutorials Posted November 30, 2009 Report Share Posted November 30, 2009 I just finished my Ajax Submit Tut. It's not the best, but it's one way to do it for a person with limited knowledge of PHP/JS (like me). Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted November 30, 2009 Report Share Posted November 30, 2009 I just finished my Ajax Submit Tut. It's not the best, but it's one way to do it for a person with limited knowledge of PHP/JS (like me). Nice work, Eric. Works fine on FF3.5.5 Ubuntu 9.10 with or without js. Quote Link to comment Share on other sites More sharing options...
PicnicTutorials Posted November 30, 2009 Report Share Posted November 30, 2009 Thanks Jim! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.