943,022 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3817
  • PHP RSS
Jul 20th, 2010
0

PHP form Mail & File Upload <?php if(isset($_POST['submit'])) doesn't work?

Expand Post »
Hi, i'm new about PHP, and i try to insert the PHP Upload script in the php mail, but somehow i don't get it to work!

this actually goes to header:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if(isset($_POST['submit'])) {
  3.  
  4. $errors = array();
  5.  
  6. $allowed_filetypes = array('.pdf','.zip','.rar');
  7. $max_filesize = 52428800;
  8. $upload_path = './uploads_SS/';
  9.  
  10. $filename = $_FILES['userfile']['name'];
  11. $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
  12.  
  13. if(!in_array($ext,$allowed_filetypes))
  14. $errors[] = "The file you attempted to upload is not allowed.";
  15.  
  16. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
  17. $errors[] = "The file you attempted to upload is too large.";
  18.  
  19. if(!is_writable($upload_path))
  20. $errors[] = "You cannot upload to the specified directory, please CHMOD it to 777.";
  21.  
  22. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
  23. echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>';
  24. else
  25. echo 'There was an error during the file upload. Please try again.';
  26.  
  27. if($_POST['fname'] == "") {
  28. $errors[] = "The First Name field is empty";
  29. }
  30.  
  31. if(count($errors) == 0) {
  32. $sendto = "someone@email.com";
  33. $title = "Application Form Submit";
  34. $fname = $_POST['fname'];
  35. $lname = $_POST['lname'];
  36. $Email = $_POST['Email'];
  37. $title_s = $_POST['title_s'];
  38. $dob = $_POST['dob'];
  39. $mob = $_POST['mob'];
  40. $yob = $_POST['yob'];
  41. $country = $_POST['country'];
  42. $saddress = $_POST['saddress'];
  43. $city = $_POST['city'];
  44. $zip = $_POST['zip'];
  45. $phone = $_POST['phone'];
  46. $fax = $_POST['fax'];
  47. $userfile = $_POST['userfile'];
  48. $adinfo = $_POST['adinfo'];
  49. $message = <<<DATA
  50. Name: $title_s $fname $lname
  51. Email: $Email
  52. Date of Birth: $dob, $mob, $yob
  53. Country Territory: $country
  54. Street Address: $saddress
  55. City/Town: $city
  56. Postal Code: $zip
  57. Phone Number: $phone
  58. Fax Number: $fax
  59. Attachments: $userfile
  60. Additional information: $userfile
  61. DATA;
  62. if(mail($sendto, $title, $message)) {
  63. $success = true;
  64. } else {
  65. $success = false;
  66. }
  67. } else {
  68. $success = false;
  69.  
  70. }
  71. }
  72.  
  73. ?>
and this in <body>
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if(isset($_POST['submit'])) {
  3. if($success == true && count($errors) == 0) {
  4. echo "&nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000'>Your Submission has been Completed.</font>";
  5. }
  6. if(count($errors) == 0 && $success == false && isset($_POST['submit'])) {
  7. echo '&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000">There was a problem with our form. Please email us directly via <a href="mailto:someone@email.com">someone@email.com</a>, thank you.</font>';
  8. }
  9.  
  10. if($success == false && count($errors) > 0 && isset($_POST['submit'])) {
  11. echo "<ul>";
  12. foreach($errors as $e) {
  13. echo "<font color='#FF0000'><li>$e</li></font>";
  14. }
  15. echo "</ul>";
  16. }
  17. }
  18.  
  19. ?>
I know the script above isn't clean!!
but I'm new on it
thank you very much for your help!
Last edited by Charles1718; Jul 20th, 2010 at 9:41 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Charles1718 is offline Offline
5 posts
since Jul 2010
Jul 20th, 2010
0
Re: PHP form Mail & File Upload <?php if(isset($_POST['submit']))
This works for me:
PHP Syntax (Toggle Plain Text)
  1. //File upload
  2.  
  3. // Where the file is going to be placed
  4. $target_path = "uploads/";
  5.  
  6. // Add the original filename to our target path.
  7. //Result is "uploads/filename.extension"
  8. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
  9.  
  10. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  11. echo "The file ". basename( $_FILES['uploadedfile']['name']).
  12. " has been uploaded";
  13. } else{
  14. echo "There was an error uploading the file, please try again!";
  15. }
  16.  
  17. //End of file upload

'uploadedfile' is the name of the 'file' input type element in the HTML form.
Last edited by levsha; Jul 20th, 2010 at 11:14 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Jul 20th, 2010
0
Re: PHP form Mail & File Upload <?php if(isset($_POST['submit']))
Hi levsh!! thanks!!, but is there any option available for only $allowed_filetypes?
thank you very much!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Charles1718 is offline Offline
5 posts
since Jul 2010
Jul 20th, 2010
0
Re: PHP form Mail & File Upload <?php if(isset($_POST['submit']))
Hi levsh!! thanks!!, but is there any option available for only $allowed_filetypes?
thank you very much!
I'm sure there is. I just haven't gotten to that point myself.
I'm having trouble attaching an uploaded file to an email. When I get this to working, I'll worry about the allowed filetypes.
Reputation Points: 10
Solved Threads: 0
Junior Poster
levsha is offline Offline
137 posts
since Nov 2009
Aug 19th, 2010
0
Re: PHP form Mail & File Upload <?php if(isset($_POST['submit']))
i changed you body code replace your 'body' code with this and let me knw results ->

<?php

if(isset($_POST['submit'])){
if($success==true&&count($errors)==0){
echo"&nbsp;&nbsp;&nbsp;&nbsp;<fontcolor='#FF0000'>YourSubmissionhasbeenCompleted.</font>";

}

if(count($errors)==0&&$success==false&&isset($_POST['submit'])){

echo'&nbsp;&nbsp;&nbsp;&nbsp;<fontcolor="#FF0000">Therewasaproblemwithourform.Pleaseemailusdirectlyvia<ahref="mailto:someone@email.com">someone@email.com</a>,thankyou.</font>';

}



if($success==false&&count($errors)>0&&isset($_POST['submit'])){

echo"<ul>";

//foreach($errorsas$e){

echo"<fontcolor='#FF0000'><li>$e</li></font>";

//}

echo"</ul>";

}

}

?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xiles is offline Offline
4 posts
since Aug 2010
Sep 7th, 2010
0
Re: PHP form Mail & File Upload <?php if(isset($_POST['submit']))
thank you my frind .................
Reputation Points: 10
Solved Threads: 0
Newbie Poster
abogadooo is offline Offline
1 posts
since Sep 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help with my Register Script
Next Thread in PHP Forum Timeline: cannot modify headers session start





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC