authenticx Posted August 27, 2009 Share Posted August 27, 2009 Hi everyone. I am a novice web coder first off, I was looking for some help with a problem I am having. I work for an IT firm and have been tasked with fixing a form on one of our customer's website that people can fill out and send their resume to the company. I have made the form with validation and captcha. I have two pages. For the time being they are called test.php and formmailcaptcha.php. The test.php has the form, the validation script, and the captcha image. Once validation is satisfied and passes captcha the form submits to formmail.php where the e-mail is built and sent, then redirects to a thankyou.html page. Everything works except the attachment. The e-mail builds and e-mails correctly as far as format and it does attach a file however it is a bogus file and not the file that was supposedly attached. I should say that the initial version of the form I made built and sent all on the same page and attached the file correctly. It is since I implimented captcah and submit to another page that teh file isn't attaching. All the info filled out is submitted to the formmailcaptcha.php page except the attachment. Other than the file attachment, all the info is posted and built into the email and sent. If someone can take a look at my code and offer some advice that would be great. Please keep in mind I am not an advanced coder. It took me two days to learn what I have so far. The pages can be viewed/tested at www.superiorengineering.com/test.php. I created an e-mail account and pointed the form to it so you can see what the e-mail looks like when it is sent. The email is "[email protected]" and the password is "webcode". Any advice is greatly appreciated. Please do not mess with the email so forum members can use it to view results of the form submission and help them see what is going on. Link to comment https://forums.phpfreaks.com/topic/172184-form-submission-and-file-attachment/ Share on other sites More sharing options...
authenticx Posted August 27, 2009 Author Share Posted August 27, 2009 HERE IS THE CODE FOR EACH PAGE::::: (minus the header and the background/body junk) TEST.PHP <script language="javascript" type="text/javascript"> <!-- hide script from older browsers function validateForm(contact) { if(""==document.forms.contact.who.value) { alert("Please enter your full name."); document.forms.contact.who.focus(); return false; } if(""==document.forms.contact.home.value) { alert("Please enter your home phone number."); document.forms.contact.home.focus() return false; } if(""==document.forms.contact.email.value) { alert("Please enter your email address."); document.forms.contact.email.focus() return false; } if(""==document.forms.contact.address.value) { alert("Please enter your street address."); document.forms.contact.address.focus() return false; } if(""==document.forms.contact.city.value) { alert("Please enter your city."); document.forms.contact.city.focus() return false; } if(""==document.forms.contact.state.value) { alert("Please enter your state."); document.forms.contact.state.focus() return false; } if(""==document.forms.contact.zip.value) { alert("Please enter your zip."); document.forms.contact.zip.focus() return false; } } stop hiding script --> </script> </HEAD> <form name="contact" method="post" action="/scripts/formmailcaptcha.php" onSubmit="return validateForm(contact);" /> <input type="hidden" name="action" value="send" /> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <pre><p><font color="#000000">Full Name: <input name="who" size="20" /></p> <p><font color="#000000">Address: <input name="address" size="20" /></p> <p><font color="#000000">City: <input name="city" size="20" /></p> <p><font color="#000000">State: <input name="state" size="20" /></p> <p><font color="#000000">Zip: <input name="zip" size="20" /></p> <p><font color="#000000">Country: <input name="country" size="20" /></p> <p><font color="#000000">Home Phone: <input name="home" size="20" /></p> <p><font color="#000000">Work Phone: <input name="work" size="20" /></p> <p><font color="#000000">May We contact you at work? <input type="radio" name="radiobutton" checked value="yes">yes <input type="radio" name="radiobutton" value="no">No</p> <p><font color="#000000">Email: <input name="email" size="20" /></p> <p><font color="#000000">Engineering areas you are interested in: <textarea name="eng" rows="5" cols="20"></textarea></p> <p><font color="#000000">Education/Degrees Held: <textarea name="edu" rows="5" cols="20"></textarea></p> <br /> <font color="#000000">Please Attach Your Resume: <input type="file" name="attachment" size="50" /> <p><br /><center><input type="submit" name="submit" value="Submit" /></center></p></pre> <CENTER><TABLE> <tr> <td colspan="2"><div><span style='margin:5px;float:left;'><img src="../securimage/securimage_show.php" border='0' width=180 height=50></span><span style='margin:5px;float:left;'>Enter the code shown:<br><input type="text" name="captcha_code" size="10" maxlength="6" /></span><br clear='all'></div></td> </tr> </TABLE></CENTER> <P ALIGN="CENTER">Thank you. Your interest is appreciated.</P> </BODY> </HTML> FORMMAILCAPTCHA.PHP <?php session_start(); ?> <?PHP include_once '../securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_REQUEST['captcha_code']) == false) { die('The code you entered was incorrect. Go back and try again. <a href="javascript: history.back();">back</a>'); } ?> <?php $name = 'supereng.com'; $subject = 'WWW Form Submission'; $result = 'Below are the results from a web submitted resume form:'; $who = stripslashes($_POST['who']); $address = stripslashes($_POST['address']); $city = stripslashes($_POST['city']); $state = stripslashes($_POST['state']); $zip = stripslashes($_POST['zip']); $country = stripslashes($_POST['country']); $home = stripslashes($_POST['home']); $work = stripslashes($_POST['work']); $radiobutton = stripslashes($_POST['radiobutton']); $email = $_POST['email']; $eng = stripslashes($_POST['eng']); $edu = stripslashes($_POST['edu']); $attachment = $_FILES['attachment']['tmp_name']; $attachment_name = $_FILES['attachment']['name']; if (is_uploaded_file($attachment)) { $fp = fopen($attachment, "rb"); $data = fread($fp, filesize($attachment)); $data = chunk_split(base64_encode($data)); fclose($fp); } $headers .= "From: $name<" . $_POST['name'] . ">\n"; $headers .= "Reply-To: $reply<" . $_POST['reply'] . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n"; $headers .= "X-Sender: $name<" . $_POST['email'] . ">\n"; $headers .= "X-Mailer: PHP4\n"; $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal $headers .= "Return-Path: <" . $_POST['reply'] . ">\n"; $headers .= "This is a multi-part message in MIME format.\n"; $headers .= "------=MIME_BOUNDRY_main_message \n"; $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n"; $message .= "------=MIME_BOUNDRY_message_parts\n"; $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; $message .= "$result\n"; $message .= "\n"; $message .= "Name: $who\n"; $message .= "Address: $address\n"; $message .= "City: $city\n"; $message .= "State: $state\n"; $message .= "Zip: $zip\n"; $message .= "Country: $country\n"; $message .= "Home Phone: $home\n"; $message .= "Work Phone: $work\n"; $message .= "May We Contact You At Work: $radiobutton\n"; $message .= "Email: $email\n"; $message .= "Engineering Fields of Interest: $eng\n"; $message .= "Education/Degrees: $edu\n"; $message .= "------=MIME_BOUNDRY_message_parts--\n"; $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message\n"; $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n"; $message .= $data; //The base64 encoded message $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message--\n"; mail("[email protected]", $subject, $message, $headers); header( "Location: http://www.supereng.com/thankyou.html" ); ?> Link to comment https://forums.phpfreaks.com/topic/172184-form-submission-and-file-attachment/#findComment-907858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.