Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP]Formularz nie wysyla pliku na e-mail
Forum PHP.pl > Forum > Przedszkole
dufia
Zaznaczam, ze mam tylko podstawowa wiedze z PHP, kod jest skopiowany i zmodyfikowany tylko troszeczke.


  1. <div id="enquiryForm2">
  2.  
  3. <?php
  4. if (count($_POST))
  5. {
  6. ////////// USTAWIENIA //////////
  7. $email = 'email'; // Adres e-mail adresata
  8. $subject = 'ENQUIRY FORM FROM WEBSITE'; // Temat listu
  9. $message = 'Thank you! Yours form have been sended. If you have done it properly, we answer you very soon!'; // Komunikat
  10. $error = 'Sorry, an error occurred, please try again. '; // Komunikat błędu
  11. $charset = 'utf-8'; // Strona kodowa
  12.  
  13. //////////////////////////////
  14.  
  15. $head =
  16. "MIME-Version: 1.0\r\n" .
  17. "Content-Type: text/plain; charset=$charset\r\n" .
  18. "Content-Transfer-Encoding: 8bit";
  19. $body = '';
  20. foreach ($_POST as $name => $value)
  21. {
  22. if (is_array($value))
  23. {
  24. for ($i = 0; $i < count($value); $i++)
  25. {
  26. $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value[$i]) : $value[$i]) . "\r\n";
  27. }
  28. }
  29. else $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value) : $value) . "\r\n";
  30. }
  31. echo mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head) ? $message : $error;
  32. }
  33.  
  34. else
  35. {
  36. ?>
  37.  
  38. <form action="?" method="post" enctype="multipart/form-data">
  39. <div id="enquiryFormInput1">
  40. <input type="text" name="firstname" size="30" maxlength="30" />
  41. </div>
  42. <div id="enquiryFormInput2">
  43. <input type="text" name="surname" size="30" maxlength="30" />
  44. </div>
  45. <div id="enquiryFormInput3">
  46. <input type="text" name="home address" size="30" maxlength="60" />
  47. </div>
  48. <div id="enquiryFormInput4">
  49. <input type="text" name="email address" size="30" maxlength="30" />
  50. </div>
  51. <div id="enquiryFormInput5">
  52. <input type="text" name="prefered work" size="30" maxlength="30" />
  53. </div>
  54. <div id="enquiryFormInput6">
  55. <input type="file" name="cv" size="19" accept="application/msword,text/plain" />
  56. </div>
  57. <div id="enquiryFormInput7">
  58. <input type="image" src="images/form_40.jpg " alt="SEND" />
  59. </div>
  60.  
  61. </form>
  62. <?php
  63. }
  64. ?>
  65. </div>


problem:

samo w sobie dziala, wysyla dane z formularza na podany adres email

Problem jest taki, ze nie dodaje zalacznika. Oryginalny skrypt wysylal tylko sam text, wiec trzeba to jakos przysyosowac, ale nie ogarniam niestety.

Zamiast dodawac plik, pobiera tylko jego nazwe i wysyla na mail sad.gif

Nie wiem za co sie zabrac, da sie wyslac ten plik bez upladowania go na serwer? czy pierwsza czynnosc jaka musze zrobic to uploadowac plik na serwer? Jak to zrobic? wstydnis.gif


Z gory dziekuje za kazda pomoc,
Pozdrawiam
nospor
Doczytaj jak się odbiera pliki z formularza, bo brak ci elementarnej wiedzy na ten temat
http://www.php.net/manual/pl/features.file...post-method.php

A następnie doczytaj jak się wysyła mailem pliki, bo i tu z wiedzą nie za dobrze
http://pl.php.net/manual/pl/function.mail.php
Przejrzyj komentarze
dufia
czytam i kumam powoli, musze plik uploadowac, potem przeczytac uzywajac fopen i dodac do wiadomosci

  1. <form action="upload.php" method="post" enctype="multipart/form-data">
  2. <div id="enquiryFormInput1">
  3. <input type="text" name="firstname" size="30" maxlength="30" />
  4. </div>
  5. <div id="enquiryFormInput2">
  6. <input type="text" name="surname" size="30" maxlength="30" />
  7. </div>
  8. <div id="enquiryFormInput3">
  9. <input type="text" name="home address" size="30" maxlength="60" />
  10. </div>
  11. <div id="enquiryFormInput4">
  12. <input type="text" name="email address" size="30" maxlength="30" />
  13. </div>
  14. <div id="enquiryFormInput5">
  15. <input type="text" name="prefered work" size="30" maxlength="30" />
  16. </div>
  17. <div id="enquiryFormInput6">
  18. <input type="hidden" name="MAX_FILE_SIZE" value="10000" />
  19. <input type="file" name="userfile" size="19" accept="application/msword,text/plain" />
  20. </div>
  21. <div id="enquiryFormInput7">
  22. <input type="image" src="images/form_40.jpg " alt="SEND" />
  23. </div>


formularz, idze do upload.php gdzie jest to

  1. <?php
  2. // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
  3. // of $_FILES.
  4.  
  5. $uploaddir = '/var/www/uploads/';
  6. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  7.  
  8. echo '<pre>';
  9. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  10. echo "File is valid, and was successfully uploaded.\n";
  11. } else {
  12. echo "Possible file upload attack!\n";
  13. }
  14.  
  15. echo 'Here is some more debugging info:';
  16. print_r($_FILES);
  17.  
  18. print "</pre>";
  19.  
  20. ?>




i dostaje niestety possible file upload attack sad.gif


musze zmienic $uploaddir? nie mam folderu tmp na serwerze, w tym problem?

link do formularza http://www.dufia.ayz.pl/root/lookfw_cate.php
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.