munky1018 Posted June 9, 2010 Share Posted June 9, 2010 Newb issue here. I'm trying to collect data from fields to send in an e-mail to myself and upload a file to a directory on our website. It worked once but our system crashed and I had to use a back-up. Now it does not upload and only e-mails me the "email" field and hidden "subject" field. Any help would be appreciated. I've spent way to much time trying to figure it out. <?php if (isset($_REQUEST['desired_position']) && isset($_REQUEST['first_name']) && isset($_REQUEST['last_name']) && isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $desired_position = $_REQUEST['desired_position'] ; $first_name = $_REQUEST['first_name'] ; $last_name = $_REQUEST['last_name'] ; $address = $_REQUEST['address'] ; $address2 = $_REQUEST['address2'] ; $city = $_REQUEST['city'] ; $state = $_REQUEST['state'] ; $zipcode = $_REQUEST['zipcode'] ; $daytime_phone = $_REQUEST['daytime_phone'] ; $evening_phone = $_REQUEST['evening_phone'] ; $email = $_REQUEST['email'] ; $website = $_REQUEST['website'] ; $cover_letter = $_REQUEST['cover_letter'] ; $fromemail = 'name@domain.com' ; $resumelocation = 'http://www.domain.com/uploads/' ; $subject = $_REQUEST['subject'] ; if($desired_position == ""){ $desired_position .= "n/a"; } if($first_name == ""){ $first_name .= "n/a"; } if($last_name == ""){ $last_name .= "n/a"; } if($address == ""){ $address .= "n/a"; } if($address2 == ""){ $address2 .= "n/a"; } if($city == ""){ $city .= "n/a"; } if($state == ""){ $state .= "n/a"; } if($zipcode == ""){ $zipcode .= "n/a"; } if($daytime_phone == ""){ $daytime_phone .= "n/a"; } if($evening_phone == ""){ $evening_phone .= "n/a"; } if($email == ""){ $email .= "n/a"; } if($website == ""){ $website .= "n/a"; } if($cover_letter == ""){ $cover_letter .= "n/a"; } // Configuration $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation. $max_filesize = 1820000; // Maximum filesize in BYTES. $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to. $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename)) echo 'Your application has been submitted successfully.'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . $message = " Desired Position : $desired_position \n Contact: $first_name \n Email: $last_name \n Address: $address \n Address 2: $address2 \n City: $city \n State: $state \n Zipcode: $zipcode \n Daytime Phone: $daytime_phone \n Evening Phone: $evening_phone \n E-mail: $email \n Website/Portfolio: $website \n Cover Letter/Comments: $cover_letter \n Resume Location: $resumelocation \n Subject: $subject"; mail( "name@domain.com", "$subject", $message, "From: $fromemail" ); { header ('Location: http://www.domain.com/submitted.php'); exit (); } } else //if "email" is not filled out, display the form { echo "Please complete entire form."; } ?> <form id="form_211871" class="appnitro" enctype="multipart/form-data" method="post" action="<?= $_SERVER['PHP_SELF']; ?>"> <ul> <li id="li_7" > <label class="description" for="element_7">Desired Position </label> <div> <input id="element_7" name="desired_position" class="element text large" type="text" maxlength="255" value=""/> </div> <p class="guidelines" id="guide_7"><small>Please state which position you are interested in.</small></p> </li> <li id="li_4" > <label class="description" for="element_4_1">Name </label> <span> <input id="element_4_1" name="first_name" class="element text" maxlength="255" size="28" value=""/> <label>First</label> </span> <span> <input id="element_4_2" name="last_name" class="element text" maxlength="255" size="28" value=""/> <label>Last</label> </span> </li> <li id="li_1" > <label class="description" for="element_1_1">Address </label> <div> <input id="element_1_1" name="address" class="element text large" value="" type="text"/> <label for="element_1_1">Street Address</label> </div> <div> <input id="element_1_2" name="address2" class="element text large" value="" type="text"/> <label for="element_1_2">Address Line 2</label> </div> <div class="left"> <input id="element_1_3" name="city" class="element text medium" value="" type="text"/> <label for="element_1_3">City</label> </div> <div class="right"> <input id="element_1_4" name="state" class="element text medium" value="" type="text"/> <label for="element_1_4">State</label> </div> <div class="left"> <input id="element_1_5" name="zipcode" class="element text medium" maxlength="15" value="" type="text"/> <label for="element_1_5">Zip Code</label> </div> </li> <li id="li_2" > <label class="description" for="element_2_1">Daytime Phone </label> <span> <input id="element_2_1" name="daytime_phone" class="element text" size="13" maxlength="13" value="" type="text"/> <label for="element_2_1">(###) ###-####</label> </span> </li> <li id="li_3" > <label class="description" for="element_3_1">Evening Phone </label> <span> <input id="element_3_1" name="evening_phone" class="element text" size="13" maxlength="13" value="" type="text"/> <label for="element_3_1">(###) ###-####</label> </span> </li> <li id="li_5" > <label class="description" for="element_5">E-mail </label> <div> <input id="element_5" name="email" class="element text medium" type="text" maxlength="255" value=""/> </div> </li> <li id="li_6" > <label class="description" for="element_6">Web Site / Portfolio </label> <div> <input id="element_6" name="website" class="element text medium" type="text" maxlength="255" value="http://"/> </div> </li> <li id="li_9" > <label class="description" for="element_9">Upload a Resume </label> <div> <input id="element_9" name="uploadfile" class="element file" type="file"/> </div> <p class="guidelines" id="guide_9"><small>File types accepted. .DOC, .PDF, .TXT</small></p> </li> <li id="li_8" > <label class="description" for="element_8">Cover Letter / Comments </label> <div> <textarea id="element_8" name="cover_letter" class="element textarea large"></textarea> </div> </li> <li class="buttons"> <input type="hidden" name="required" value="email,phone"/> <!-- Required Fields --> <input type="hidden" name="subject" value="Job Posting"/> <input type="image" src="../images/bluearrow.png" title="Submit Resume" width="20" height="19" class="formbutton" value="Submit Resume"/>Submit Resume </li> </ul> </form> <?php ?> Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/ Share on other sites More sharing options...
syed Posted June 9, 2010 Share Posted June 9, 2010 Do you get any errors? Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1069943 Share on other sites More sharing options...
munky1018 Posted June 9, 2010 Author Share Posted June 9, 2010 No errrors come up and the page redirects like it went through fine. It just doesn't upload the file or send the full "message" Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1069945 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2010 Share Posted June 9, 2010 While debugging, remove the redirect. Since you're using the POST method, change all the $_REQUEST to $_POST and put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> at the start of the script. This will dump what's being submitted to the script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1069968 Share on other sites More sharing options...
munky1018 Posted June 9, 2010 Author Share Posted June 9, 2010 This is what I have now but I still get the same result. <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; if (isset($_POST['desired_position']) && isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email'])) //if "email" is filled out, send email { //send email $desired_position = $_POST['desired_position'] ; $first_name = $_POST['first_name'] ; $last_name = $_POST['last_name'] ; $address = $_POST['address'] ; $address2 = $_POST['address2'] ; $city = $_POST['city'] ; $state = $_POST['state'] ; $zipcode = $_POST['zipcode'] ; $daytime_phone = $_POST['daytime_phone'] ; $evening_phone = $_POST['evening_phone'] ; $email = $_POST['email'] ; $website = $_POST['website'] ; $cover_letter = $_POST['cover_letter'] ; $fromemail = 'nick.simon@trafficbuildersusa.com' ; $resumelocation = 'http://www.trafficbuildersusa.com/test/careers/uploadsxyz_traff/' ; $subject = $_POST['subject'] ; if($desired_position == ""){ $desired_position .= "n/a"; } if($first_name == ""){ $first_name .= "n/a"; } if($last_name == ""){ $last_name .= "n/a"; } if($address == ""){ $address .= "n/a"; } if($address2 == ""){ $address2 .= "n/a"; } if($city == ""){ $city .= "n/a"; } if($state == ""){ $state .= "n/a"; } if($zipcode == ""){ $zipcode .= "n/a"; } if($daytime_phone == ""){ $daytime_phone .= "n/a"; } if($evening_phone == ""){ $evening_phone .= "n/a"; } if($email == ""){ $email .= "n/a"; } if($website == ""){ $website .= "n/a"; } if($cover_letter == ""){ $cover_letter .= "n/a"; } // Configuration $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation. $max_filesize = 1820000; // Maximum filesize in BYTES. $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to. $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename)) echo 'Your application has been submitted successfully.'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . $message = " Desired Position : $desired_position \n Contact: $first_name \n Email: $last_name \n Address: $address \n Address 2: $address2 \n City: $city \n State: $state \n Zipcode: $zipcode \n Daytime Phone: $daytime_phone \n Evening Phone: $evening_phone \n E-mail: $email \n Website/Portfolio: $website \n Cover Letter/Comments: $cover_letter \n Resume Location: $resumelocation \n Subject: $subject"; mail( "nick.simon@trafficbuildersusa.com", "$subject", $message, "From: $fromemail" ); { header ('Location: http://www.trafficbuildersusa.com/'); exit (); } } else //if "email" is not filled out, display the form { echo "Please complete entire form."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1069976 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2010 Share Posted June 9, 2010 Do you get a dump of what's being submitted? If so post the output here. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070027 Share on other sites More sharing options...
munky1018 Posted June 9, 2010 Author Share Posted June 9, 2010 This is all I get in the e-mail. Subject: Job Posting Email: email@aol.com Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070028 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2010 Share Posted June 9, 2010 Not the email contents. The line <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> Should print what's being submitted. That's what you need to show us. But you have to comment out or remove <?php header ('Location: http://www.trafficbuildersusa.com/'); ?> to see it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070031 Share on other sites More sharing options...
munky1018 Posted June 9, 2010 Author Share Posted June 9, 2010 I removed that line completely and it doesn't not print. It acts like always. <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; if (isset($_POST['desired_position']) && isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email'])) //if "email" is filled out, send email { //send email $desired_position = $_POST['desired_position'] ; $first_name = $_POST['first_name'] ; $last_name = $_POST['last_name'] ; $address = $_POST['address'] ; $address2 = $_POST['address2'] ; $city = $_POST['city'] ; $state = $_POST['state'] ; $zipcode = $_POST['zipcode'] ; $daytime_phone = $_POST['daytime_phone'] ; $evening_phone = $_POST['evening_phone'] ; $email = $_POST['email'] ; $website = $_POST['website'] ; $cover_letter = $_POST['cover_letter'] ; $fromemail = 'nick.simon@trafficbuildersusa.com' ; $resumelocation = 'http://www.trafficbuildersusa.com/test/careers/uploadsxyz_traff/' ; $subject = $_POST['subject'] ; if($desired_position == ""){ $desired_position .= "n/a"; } if($first_name == ""){ $first_name .= "n/a"; } if($last_name == ""){ $last_name .= "n/a"; } if($address == ""){ $address .= "n/a"; } if($address2 == ""){ $address2 .= "n/a"; } if($city == ""){ $city .= "n/a"; } if($state == ""){ $state .= "n/a"; } if($zipcode == ""){ $zipcode .= "n/a"; } if($daytime_phone == ""){ $daytime_phone .= "n/a"; } if($evening_phone == ""){ $evening_phone .= "n/a"; } if($email == ""){ $email .= "n/a"; } if($website == ""){ $website .= "n/a"; } if($cover_letter == ""){ $cover_letter .= "n/a"; } // Configuration $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation. $max_filesize = 1820000; // Maximum filesize in BYTES. $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to. $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename)) echo 'Your application has been submitted successfully.'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . $message = " Desired Position : $desired_position \n Contact: $first_name \n Email: $last_name \n Address: $address \n Address 2: $address2 \n City: $city \n State: $state \n Zipcode: $zipcode \n Daytime Phone: $daytime_phone \n Evening Phone: $evening_phone \n E-mail: $email \n Website/Portfolio: $website \n Cover Letter/Comments: $cover_letter \n Resume Location: $resumelocation \n Subject: $subject"; mail( "nick.simon@trafficbuildersusa.com", "$subject", $message, "From: $fromemail" ); } Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070037 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2010 Share Posted June 9, 2010 If nothing is printing, then you're not using the file you've been updating. Make absolutely sure, you're using the updated file. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070039 Share on other sites More sharing options...
munky1018 Posted June 9, 2010 Author Share Posted June 9, 2010 I just figured it out. There is a different php file running higher in the page that was causing a conflict. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/#findComment-1070050 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.