ScottAllenNet Posted June 22, 2012 Share Posted June 22, 2012 Hi Guys, I am having some trouble creating a form process due to a simple lack of knowlegde. Here is my current php code: <?php $EmailFrom = "website@harrisonpearce.com"; $EmailTo = "register@harrisonpearce.com"; $Subject = "New Candidate Registration"; $name = Trim(stripslashes($_POST['name'])); $email = Trim(stripslashes($_POST['email'])); $telephone = Trim(stripslashes($_POST['telephone'])); $location = Trim(stripslashes($_POST['location'])); $attachcv = Trim(stripslashes($_POST['attachcv'])); $coveringletter = Trim(stripslashes($_POST['coveringletter'])); // validation $validationOK=true; if (Trim($name)=="") $validationOK=false; if (Trim($email)=="") $validationOK=false; if (Trim($telephone)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; exit; } // email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $telephone; $Body .= "\n"; $Body .= "Location: "; $Body .= $location; $Body .= "\n"; $Body .= "Attach CV: "; $Body .= $attachcv; $Body .= "\n"; $Body .= "Covering Letter: "; $Body .= $coveringletter; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; } ?> And here is the front end HTML code: <form name="submit-cv" id="submit-cv" action="_layout/php/submit-cv.php" method="post"> <table> <tbody><tr> <td> Your Name: <font color="#DA1623">*</font><br /> <input id="name" class="text" type="text" value="" name="name"> </td> <td> Email Address: <font color="#DA1623">*</font><br /> <input id="email" class="text" type="text" value="" name="email"> </td> </tr> <tr> <td> Telephone: <font color="#DA1623">*</font><br /> <input id="telephone" class="text" type="text" value="" name="telephone"> </td> <td> Location:<br /> <input id="location" class="text" type="text" value="" name="location"> </td> </tr> <tr> <td colspan="2"> Attach CV:<br /> <input type="file" name="attachcv" id="attachcv" /> </td> </tr> <tr> <td colspan="2"> Covering Letter:<br /> <textarea name="coveringletter" rows="5" cols="20"></textarea> </td> </tr> </tbody></table> <input type="submit" name="submit" value="Send Details"> </form> At the moment, as you can see the attach CV field is a simple text entry field - I want to make this a file upload field which will then attach the file to the email that it sends to me. Any assistance in this would be fantastic. Best, Scott. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/ Share on other sites More sharing options...
boompa Posted June 22, 2012 Share Posted June 22, 2012 Start by reading the manual. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356076 Share on other sites More sharing options...
ScottAllenNet Posted June 22, 2012 Author Share Posted June 22, 2012 Quote Start by reading the manual. Thanks for that - can't seem to find much on the attaching of the file into the email that the back end sends though? Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356077 Share on other sites More sharing options...
litebearer Posted June 22, 2012 Share Posted June 22, 2012 re: uploading files - http://www.tizag.com/phpT/fileupload.php/ re: attaching files to email - http://webcheatsheet.com/php/send_email_text_html_attachment.php Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356094 Share on other sites More sharing options...
ScottAllenNet Posted June 22, 2012 Author Share Posted June 22, 2012 Quote re: uploading files - http://www.tizag.com/phpT/fileupload.php/ re: attaching files to email - http://webcheatsheet.com/php/send_email_text_html_attachment.php Thanks for your help but I am still a little lost as to how best integrate that with my existing code. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356112 Share on other sites More sharing options...
litebearer Posted June 22, 2012 Share Posted June 22, 2012 My suggestion is to start small ie create a simple test file using the tutorial provided above to see how to upload a file. Once you do that you will see how to change your actual scripts. Most new phpers try to do too many things at once. build your scripts in increments. Makes life sooooo much easier when trying to debug. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356118 Share on other sites More sharing options...
ScottAllenNet Posted June 22, 2012 Author Share Posted June 22, 2012 Quote My suggestion is to start small ie create a simple test file using the tutorial provided above to see how to upload a file. Once you do that you will see how to change your actual scripts. Most new phpers try to do too many things at once. build your scripts in increments. Makes life sooooo much easier when trying to debug. Ok so I know have a script that can upload the file but it really throws me on how to email it as an attachment??? <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356138 Share on other sites More sharing options...
litebearer Posted June 22, 2012 Share Posted June 22, 2012 1. has the file been successfully uploaded? 2. do you know the path to the file? Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356150 Share on other sites More sharing options...
ScottAllenNet Posted June 22, 2012 Author Share Posted June 22, 2012 Quote 1. has the file been successfully uploaded? 2. do you know the path to the file? Yep I know the location of the file and the path is /test/uploads Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356151 Share on other sites More sharing options...
ScottAllenNet Posted June 22, 2012 Author Share Posted June 22, 2012 Sorry: http://harrisonpearce.com/test/uploads/ Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356153 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 Can anyone else help? Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356383 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 Seems like the page you linked does not exists. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356384 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 Thats right, it is the destination for the script to upload the file. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356385 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 On the page where you are running the PHP, echo this. <?php echo $_SERVER['PHP_SELF']; ?> What value do you get? Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356388 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 /test/index.php Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356391 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 Okay, check if the file exists in your folder. If the file exists, you can continue to step 2 where you attach the file to the email. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356394 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 Yeah - as noted before i can confirm the file does upload successfully I just can't grasp how to attach that said file to an outgoing email and then erase the file. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356410 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 Check out this tutorial. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356411 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 Thanks - but each submission of the form will be sending a different document - that doesn't really help me. Perhaps this will help show the context of what I am trying to achieve: http://www.harrisonpearce.com/submit-your-cv Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356412 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 this might help <?php $type = mime_content_type($file); ?> it would produce the file type of the file. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356414 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 I really appreciate your help but I think you overestimate my php abilites. I have no idea how to implement this. What I have produces really is the limit. If possible, can you explain in the simplist of terms, how to turn the following into a form that will upload and email the document along with the form: <form name="submit-cv" id="submit-cv" action="_layout/php/submit-cv.php" method="post"> <table> <tbody><tr> <td> Your Name: <font color="#DA1623">*</font><br /> <input id="name" class="text" type="text" value="" name="name"> </td> <td> Email Address: <font color="#DA1623">*</font><br /> <input id="email" class="text" type="text" value="" name="email"> </td> </tr> <tr> <td> Telephone: <font color="#DA1623">*</font><br /> <input id="telephone" class="text" type="text" value="" name="telephone"> </td> <td> Location:<br /> <input id="location" class="text" type="text" value="" name="location"> </td> </tr> <tr> <td colspan="2"> Attach CV:<br /> <input type="file" name="attachcv" id="attachcv" /> </td> </tr> <tr> <td colspan="2"> Covering Letter/Other:<br /> <textarea name="coveringletter" rows="5" cols="20"></textarea> </td> </tr> </tbody></table> <input type="submit" name="submit" value="Send Details"> </form> <?php // get posted data into local variables $EmailFrom = "website@harrisonpearce.com"; $EmailTo = "register@harrisonpearce.com"; $Subject = "New Candidate Registration"; $name = Trim(stripslashes($_POST['name'])); $email = Trim(stripslashes($_POST['email'])); $telephone = Trim(stripslashes($_POST['telephone'])); $location = Trim(stripslashes($_POST['location'])); $coveringletter = Trim(stripslashes($_POST['coveringletter'])); // validation $validationOK=true; if (Trim($name)=="") $validationOK=false; if (Trim($email)=="") $validationOK=false; if (Trim($telephone)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $telephone; $Body .= "\n"; $Body .= "Location: "; $Body .= $location; $Body .= "\n"; $Body .= "Covering Letter: "; $Body .= $coveringletter; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; } ?> Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356427 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 This should work just fine. I have not personally tested it out. But it looks fine <?php // upload the file to the server $filename = basename( $_FILES['uploadedfile']['name']); // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['file']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $file = file_get_contents($target_path); // get posted data into local variables $EmailFrom = "website@harrisonpearce.com"; $EmailTo = "register@harrisonpearce.com"; $Subject = "New Candidate Registration"; $name = Trim(stripslashes($_POST['name'])); $email = Trim(stripslashes($_POST['email'])); $telephone = Trim(stripslashes($_POST['telephone'])); $location = Trim(stripslashes($_POST['location'])); $coveringletter = Trim(stripslashes($_POST['coveringletter'])); // validation $validationOK=true; if (Trim($name)=="") $validationOK=false; if (Trim($email)=="") $validationOK=false; if (Trim($telephone)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; exit; } // prepare email body text $Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" $Body .= ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $telephone; $Body .= "\n"; $Body .= "Location: "; $Body .= $location; $Body .= "\n"; $Body .= "Covering Letter: "; $Body .= $coveringletter; $Body .= "\n"; $Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file)); // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">"; } ?> I've just updated the code. Saw some syntax errors. Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356434 Share on other sites More sharing options...
ScottAllenNet Posted June 23, 2012 Author Share Posted June 23, 2012 Thanks man! I seem to get this error though: Parse error: syntax error, unexpected T_VARIABLE in /homepages/7/d393500880/htdocs/harrisonpearce/_layout/php/submit-cv.php on line 54 Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356475 Share on other sites More sharing options...
Barand Posted June 23, 2012 Share Posted June 23, 2012 missing ';' at end of this line $Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356494 Share on other sites More sharing options...
ScottAllenNet Posted June 24, 2012 Author Share Posted June 24, 2012 Quote missing ';' at end of this line $Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" Thanks buddy - but it now shows this error: There was an error uploading the file, please try again! Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/_layout/php/submit-cv.php on line 70 Link to comment https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/#findComment-1356505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.