Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][PHP] Proźba o pomoc w edycji skryptu
marjaan
post 13.10.2009, 18:27:57
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 13.10.2009

Ostrzeżenie: (0%)
-----


Witam wszystkich.

Jestem początkujący jeśli chodzi i PHP

Czytałem wiele postów na temat wysyłania maila z załącznikiem, próbowałem na jego podstawie samodzielnie modyfikować skrypt który posiadam, tak by za jego pomocą można było wysyłać więcej niż jeden załącznik... niestety bezskutecznie sadsmiley02.gif

Byłbym wdzięczny jeśli pomoglibyście mi w edycji tego skryptu, tak by mógł wysyłać wiele załączników, z góry dziękuję

  1. <?php
  2. $arrLocale = array( "pl_PL", "polish_pol" );
  3. setlocale( LC_ALL, $arrLocale );
  4.  
  5. $data = strftime("%A, %d %B %Y");
  6. $boundary = "-->===_54654747_===<---->>4255==_";
  7.  
  8. $head = "From: $email\n";
  9. $head = $head . "Reply-To: $email\n";
  10. $head = $head . "X-Mailer: PHP\n";
  11. $head = $head . "X-Sender: $email\n";
  12. $head = $head . "MIME-version: 1.0\n";
  13. $head = $head . "Content-type: multipart/mixed; ";
  14. $head = $head . "boundary=\"$boundary\"\n";
  15. $head = $head . "Content-transfer-encoding: 7BIT\n";
  16. $head = $head . "X-attachments: $filename_name;\n\n";
  17.  
  18.  
  19.  
  20. $mesg = "--" . $boundary . "\n";
  21. $mesg = $mesg . "Content-Type: text/plain; charset=\"iso-8859-2\"\n\n";
  22. $mesg = $mesg
  23.  
  24. .$numer = "Numer zlecenia: $numer" ." "
  25. .$data1 = "Data: $data1" ."\n"
  26. .$zleceniodawca = "Zleceniodawca: $zleceniodawca" ."\n"
  27. .$z_jezyka = "Tlumaczenie z jezyka: $z_jezyka" ." "
  28. .$na_jezyk = "na jezyk: $na_jezyk" ."\n"
  29. .$dane = "Dane do rachunku: $dane" ."\n"
  30. .$telefon = "Telefon: $telefon" ."\n"
  31. .$uwagi = "Uwagi: $uwagi" ."\n"
  32. .$www = "Strona www: $www" ."\n"
  33. .$email = "E-MAIL: $email" ."\n"
  34. .$data = "Wysłano dnia: $data" ."\n";
  35.  
  36. $mesg = $mesg . "--" . $boundary . "\n";
  37. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  38. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  39. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  40. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  41. $mesg = $mesg . "--" . $boundary . "-- \n";
  42.  
  43.  
  44.  
  45. function fileopenanddecode($file) {
  46. if (is_readable($file)) {
  47. $fd = fopen($file, "r");
  48. $plik = fread($fd, filesize($file));
  49. $encoded = chunk_split(base64_encode($plik));
  50. fclose($fd);
  51. }
  52. return $encoded;
  53. }
  54.  
  55.  
  56.  
  57. mail("mojmail@wp.pl", "ZLECENIE ON LINE", $mesg , $head);
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. ?>
  65.  
  66. <html>
  67.  
  68. <head>
  69. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  70. <meta http-equiv="Content-Language" content="pl">
  71. <link rel="Shortcut icon" href="images/ikonka.ico" />
  72. <title>Zlecenie</title>
  73. </head>
  74.  
  75. <body bgcolor="#9D826D">
  76.  
  77. <p align="left">
  78. <p></p>
  79. <p></p>
  80. <font face="Arial" style="font-size: 14px" color="#FFFFFF"><b>Dziękuję, Twoje dane zostały przesłane!</b></font>
  81. <p></p>
  82. <button name="B3" onclick="java script:history.back();">Kolejne zlecenie
  83. </button></p>
  84. </body>
  85.  
  86. </html>



Na podstawie różnych postów na forum domyślam się że trzeba edytować poniższą część, ale niestety nie udało mi się tego zrobić samodzielnie

  1.  
  2. $mesg = $mesg . "--" . $boundary . "\n";
  3. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  4. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  5. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  6. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  7. $mesg = $mesg . "--" . $boundary . "-- \n";
  8.  
  9.  
  10.  
  11. function fileopenanddecode($file) {
  12. if (is_readable($file)) {
  13. $fd = fopen($file, "r");
  14. $plik = fread($fd, filesize($file));
  15. $encoded = chunk_split(base64_encode($plik));
  16. fclose($fd);
  17. }
  18. return $encoded;
  19. }
Go to the top of the page
+Quote Post
jmail
post 13.10.2009, 21:43:52
Post #2





Grupa: Zarejestrowani
Postów: 352
Pomógł: 53
Dołączył: 10.08.2009

Ostrzeżenie: (0%)
-----


nie wyważaj otwartych drzwi. weź gotową klasę http://sourceforge.net/projects/phpmailer/ i z niej skorzystaj
Go to the top of the page
+Quote Post
marjaan
post 13.10.2009, 22:43:03
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 13.10.2009

Ostrzeżenie: (0%)
-----


@jmail

wszedłem na link który mi podałeś... ściągnąłem i przejrzałem "inc.configuration.php" ...
nie wątpię że dla kogoś kto zna się na PHP i siedzi w tym od jakiegoś czasu, było by to bardzo pomocne i nieocenione...

Lecz ja, tak jak napisałem w moim pierwszym poście, jestem początkujący jeśli chodzi o PHP... i niestety nie wiem w jaki sposób mam wykorzystać Twoją radę...

Ponieważ jestem początkujący, napisałem moją prośbę na forum "przedszkole" by poprosić "was" bardziej zaawansowanych o pomoc w edycji już istniejącego skryptu...

Skrypt który już mam działa... wysyłając wszystkie treści które mi są potrzebne plus 1 załącznik... Ja potrzebuję tylko porady jak zmienić już istniejący skrypt by istniała możliwość wysyłania powiedzmy 5ciu załączników...

Zapewne trzeba powielić i zmodyfikować jakiś fragment kodu... próbowałem to robić na własną rękę metodą prób i błędów... ale bezskutecznie.

Część kodu w pliku html już edytowałem, wkleję poniżej jego fragment, w którym widnieje 5 pól, do załadowania 5 plików...

  1. Załącz plik:&nbsp;<input type="file" name="filename" size="10">
  2. <br>
  3. Załącz plik:&nbsp;<input type="file" name="filename2" size="10">
  4. <br>
  5. Załącz plik:&nbsp;<input type="file" name="filename3" size="10">
  6. <br>
  7. Załącz plik:&nbsp;<input type="file" name="filename4" size="10">
  8. <br>
  9. Załącz plik:&nbsp;<input type="file" name="filename5" size="10">


Proszę jednak o pomoc w edycji mojego skryptu PHP... by była możliwość wysłania tych 5ciu plików... bo aktualnie co prawda mogę wskazać lokalizację do 5ciu plików, ale wraz z mailem wyśle się tylko pierwszy...
Proszę o wyrozumiałość i liczę że znajdzie się ktoś na tyle życzliwy aby mi pomoc. Z góry dziękuje
Go to the top of the page
+Quote Post
jmail
post 13.10.2009, 22:56:09
Post #4





Grupa: Zarejestrowani
Postów: 352
Pomógł: 53
Dołączył: 10.08.2009

Ostrzeżenie: (0%)
-----


to powiel dla każdego pliku załącznika

  1.  
  2. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  3. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  4. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  5. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  6. $mesg = $mesg . "--" . $boundary . "-- \n";
  7.  
Go to the top of the page
+Quote Post
marjaan
post 14.10.2009, 01:30:29
Post #5





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 13.10.2009

Ostrzeżenie: (0%)
-----


@jmail

Próbowałem powielić to co napisałeś, niestety mail nadal dochodzi tylko z jednym (pierwszym) załącznikiem...
mój skrypt poprawiony wg Twoich wskazówek, wyglądał następująco, :

  1. <?php
  2. $arrLocale = array( "pl_PL", "polish_pol" );
  3. setlocale( LC_ALL, $arrLocale );
  4.  
  5. $data = strftime("%A, %d %B %Y");
  6. $boundary = "-->===_54654747_===<---->>4255==_";
  7.  
  8. $head = "From: $email\n";
  9. $head = $head . "Reply-To: $email\n";
  10. $head = $head . "X-Mailer: PHP\n";
  11. $head = $head . "X-Sender: $email\n";
  12. $head = $head . "MIME-version: 1.0\n";
  13. $head = $head . "Content-type: multipart/mixed; ";
  14. $head = $head . "boundary=\"$boundary\"\n";
  15. $head = $head . "Content-transfer-encoding: 7BIT\n";
  16. $head = $head . "X-attachments: $filename_name;\n\n";
  17.  
  18.  
  19.  
  20. $mesg = "--" . $boundary . "\n";
  21. $mesg = $mesg . "Content-Type: text/plain; charset=\"iso-8859-2\"\n\n";
  22. $mesg = $mesg
  23.  
  24. .$numer = "Numer zlecenia: $numer" ." "
  25. .$data1 = "Data: $data1" ."\n"
  26. .$zleceniodawca = "Zleceniodawca: $zleceniodawca" ."\n"
  27. .$z_jezyka = "Tlumaczenie z jezyka: $z_jezyka" ." "
  28. .$na_jezyk = "na jezyk: $na_jezyk" ."\n"
  29. .$dane = "Dane do rachunku: $dane" ."\n"
  30. .$telefon = "Telefon: $telefon" ."\n"
  31. .$uwagi = "Uwagi: $uwagi" ."\n"
  32. .$www = "Strona www: $www" ."\n"
  33. .$email = "E-MAIL: $email" ."\n"
  34. .$data = "Wysłano dnia: $data" ."\n";
  35.  
  36. // plik1
  37.  
  38. $mesg = $mesg . "--" . $boundary . "\n";
  39. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  40. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  41. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  42. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  43. $mesg = $mesg . "--" . $boundary . "-- \n";
  44.  
  45. // plik2
  46.  
  47. $mesg = $mesg . "--" . $boundary . "\n";
  48. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  49. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  50. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  51. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  52. $mesg = $mesg . "--" . $boundary . "-- \n";
  53.  
  54. // plik3
  55.  
  56. $mesg = $mesg . "--" . $boundary . "\n";
  57. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  58. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  59. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  60. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  61. $mesg = $mesg . "--" . $boundary . "-- \n";
  62.  
  63. // plik4
  64.  
  65. $mesg = $mesg . "--" . $boundary . "\n";
  66. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  67. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  68. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  69. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  70. $mesg = $mesg . "--" . $boundary . "-- \n";
  71.  
  72. // plik5
  73.  
  74. $mesg = $mesg . "--" . $boundary . "\n";
  75. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  76. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  77. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  78. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  79. $mesg = $mesg . "--" . $boundary . "-- \n";
  80.  
  81.  
  82.  
  83. function fileopenanddecode($file) {
  84. if (is_readable($file)) {
  85. $fd = fopen($file, "r");
  86. $plik = fread($fd, filesize($file));
  87. $encoded = chunk_split(base64_encode($plik));
  88. fclose($fd);
  89. }
  90. return $encoded;
  91. }
  92.  
  93. mail("dag@dag-center.com", "ZLECENIE ON LINE", $mesg , $head);
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. ?>
  101.  
  102. <html>
  103.  
  104. <head>
  105. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  106. <meta http-equiv="Content-Language" content="pl">
  107. <link rel="Shortcut icon" href="images/ikonka.ico" />
  108. <title>Zlecenie</title>
  109. </head>
  110.  
  111. <body bgcolor="#9D826D">
  112.  
  113. <p align="left">
  114. <p></p>
  115. <p></p>
  116. <font face="Arial" style="font-size: 14px" color="#FFFFFF"><b>Dziękuję, Twoje dane zostały przesłane!</b></font>
  117. <p></p>
  118. <button name="B3" onclick="java script:history.back();">Kolejne zlecenie
  119. </button></p>
  120. </body>
  121.  
  122. </html>



Próbowałem również innych kombinacji z tą częścią kodu która podałeś, mianowicie:
  1. // plik1
  2.  
  3. $mesg = $mesg . "--" . $boundary . "\n";
  4. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  5. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  6. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  7. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  8. $mesg = $mesg . "--" . $boundary . "-- \n";
  9.  
  10. // plik2
  11.  
  12. $mesg = $mesg . "--" . $boundary . "\n";
  13. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename2_name\";\n";
  14. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  15. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename2_name\"\n\n";
  16. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  17. $mesg = $mesg . "--" . $boundary . "-- \n";
  18.  
  19. // plik3
  20.  
  21. $mesg = $mesg . "--" . $boundary . "\n";
  22. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename3_name\";\n";
  23. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  24. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename3_name\"\n\n";
  25. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  26. $mesg = $mesg . "--" . $boundary . "-- \n";
  27.  
  28. // plik4
  29.  
  30. $mesg = $mesg . "--" . $boundary . "\n";
  31. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename4_name\";\n";
  32. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  33. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename4_name\"\n\n";
  34. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  35. $mesg = $mesg . "--" . $boundary . "-- \n";
  36.  
  37. // plik5
  38.  
  39. $mesg = $mesg . "--" . $boundary . "\n";
  40. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename5_name\";\n";
  41. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  42. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename5_name\"\n\n";
  43. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  44. $mesg = $mesg . "--" . $boundary . "-- \n";


Próbowałem również tak...:
  1. // plik1
  2.  
  3. $mesg = $mesg . "--" . $boundary . "\n";
  4. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  5. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  6. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  7. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  8. $mesg = $mesg . "--" . $boundary . "-- \n";
  9.  
  10. // plik2
  11.  
  12. $mesg = $mesg . "--" . $boundary . "\n";
  13. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename2_name\";\n";
  14. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  15. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename2_name\"\n\n";
  16. $mesg = $mesg . fileopenanddecode($filename2) . "\n";
  17. $mesg = $mesg . "--" . $boundary . "-- \n";
  18.  
  19. // plik3
  20.  
  21. $mesg = $mesg . "--" . $boundary . "\n";
  22. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename3_name\";\n";
  23. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  24. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename3_name\"\n\n";
  25. $mesg = $mesg . fileopenanddecode($filename3) . "\n";
  26. $mesg = $mesg . "--" . $boundary . "-- \n";
  27.  
  28. // plik4
  29.  
  30. $mesg = $mesg . "--" . $boundary . "\n";
  31. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename4_name\";\n";
  32. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  33. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename4_name\"\n\n";
  34. $mesg = $mesg . fileopenanddecode($filename4) . "\n";
  35. $mesg = $mesg . "--" . $boundary . "-- \n";
  36.  
  37. // plik5
  38.  
  39. $mesg = $mesg . "--" . $boundary . "\n";
  40. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename5_name\";\n";
  41. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  42. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename5_name\"\n\n";
  43. $mesg = $mesg . fileopenanddecode($filename5) . "\n";
  44. $mesg = $mesg . "--" . $boundary . "-- \n";


Masz może (lub ktoś inny) jeszcze jakieś prpozycję?

P.S. Ze stronki do którrj podaje link poniżej wziołęm ten skrypt, tam było opisane co i jak zrobić dla jednego pliku, ale dla kolejnych, już nie...
Może po przeczytaniu infomacji tam zawartych wpadniesz na pomysł jak pomóc mi edytować ten skrypt?
http://php.webhelp.pl/index.php?id=106&...php&ac=read

sadsmiley02.gif
Go to the top of the page
+Quote Post
jmail
post 14.10.2009, 02:17:29
Post #6





Grupa: Zarejestrowani
Postów: 352
Pomógł: 53
Dołączył: 10.08.2009

Ostrzeżenie: (0%)
-----


a gdzie masz obsługę formularza? to bym chciał zobaczyć jeszcze

spróbuj tak

  1.  
  2. <?php
  3. // array with filenames to be sent as attachment
  4. $files = array("file_1.ext","file_2.ext","file_3.ext",......);
  5. // email fields: to, from, subject, and so on
  6. $to = "mail@mail.com";
  7. $from = "mail@mail.com";
  8. $subject ="My subject";
  9. $message = "My message";
  10. $headers = "From: $from";
  11. // boundary
  12. $semi_rand = md5(time());
  13. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  14. // headers for attachment
  15. $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
  16. // multipart boundary
  17. $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
  18. $message .= "--{$mime_boundary}\n";
  19. // preparing attachments
  20. for($x=0;$x<count($files);$x++){
  21. $file = fopen($files[$x],"rb");
  22. $data = fread($file,filesize($files[$x]));
  23. fclose($file);
  24. $data = chunk_split(base64_encode($data));
  25. $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
  26. "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
  27. "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
  28. $message .= "--{$mime_boundary}\n";
  29. }
  30. // send
  31. $ok = @mail($to, $subject, $message, $headers);
  32. if ($ok) {
  33. echo "<p>mail sent to $to!</p>";
  34. } else {
  35. echo "<p>mail could not be sent!</p>";
  36. }
  37. ?>
  38.  


Ten post edytował jmail 14.10.2009, 02:21:01
Go to the top of the page
+Quote Post
marjaan
post 15.10.2009, 03:05:06
Post #7





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 13.10.2009

Ostrzeżenie: (0%)
-----


@jmail

Na wstępie chciałbym Ci podziękować za dotychczasową pomoc (wcisnąłem oczywiście również przycisk POMÓGŁ) i zadać jeszcze jedno pytanie odnośnie tego skryptu, ale o tym później...
Okazało się że dobrze kombinowaliśmy, faktycznie trzeba było powielić tą linie kodu...



@jmail

Na wstępie chciałbym Ci podziękować za dotychczasową pomoc (wcisnąłem oczywiście również przycisk POMÓGŁ) i zadać jeszcze jedno pytanie odnośnie tego skryptu, ale o tym później...
Okazało się że dobrze kombinowaliśmy, faktycznie trzeba było powielić tą linie kodu...

  1. $mesg = $mesg . "--" . $boundary . "\n";
  2. $mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
  3. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  4. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
  5. $mesg = $mesg . fileopenanddecode($filename) . "\n";
  6. $mesg = $mesg . "--" . $boundary . "-- \n";


Z jedną małą poprawką ... mianowicie tylko przy ostatnim załączniku trzeba stawiać $mesg = $mesg . "--" . $boundary . "-- \n";
Po wcześniejszych załącznikach trzeba stawiać $mesg = $mesg . "--" . $boundary . "\n"; bez dwóch "--" na końcu


Teraz mój skrypt wysyła maila i 5 załączników, ale jest spora niedogodność, mianowicie...
jeśli do formularza dołączę tylko jeden załącznik, to skrypt wyśle mi na maila i tak 5 załączników... z tym że jeden to będzie faktycznie załączony do formularza plik...
a pozostałe cztery to będą puste pliki TXT z kolejnymi nazwami... poniżej pokażę jak to wygląda...

Załączniki:
bezNazwy1.txt (0,20 kB) Zapisz <<< to jest plik zawierający treść maila
angielski.doc (41,46 kB) Zapisz <<< to jest faktycznie załączony przeze mnie do formularza załącznik
bezNazwy2.txt (0,00 kB) Zapisz <<< a reszta to puste pliki txt, wysłane w miejsce nie załączonych załączników smile.gif
bezNazwy3.txt (0,00 kB) Zapisz
bezNazwy4.txt (0,00 kB) Zapisz
bezNazwy5.txt (0,00 kB) Zapisz


Chciałbym oczywiście żeby dochodziło tylko tyle załączników ile faktycznie załączę, bez tych zbędnych pustych załączników
Czy wiesz może jaką funkcję trzeba dopisać, co zmienić w kodzie, by osiągnąć ten cel?

Oto aktualny wygląd skryptu:

  1. <?php
  2. $arrLocale = array( "pl_PL", "polish_pol" );
  3. setlocale( LC_ALL, $arrLocale );
  4.  
  5. $data = strftime("%A, %d %B %Y");
  6. $boundary = "-->===_54654747_===<---->>4255==_";
  7.  
  8. $head = "From: $email\n";
  9. $head = $head . "Reply-To: $email\n";
  10. $head = $head . "X-Mailer: PHP\n";
  11. $head = $head . "X-Sender: $email\n";
  12. $head = $head . "MIME-version: 1.0\n";
  13. $head = $head . "Content-type: multipart/mixed; ";
  14. $head = $head . "boundary=\"$boundary\"\n";
  15. $head = $head . "Content-transfer-encoding: 7BIT\n";
  16. $head = $head . "X-attachments: $filename_name;\n\n";
  17.  
  18.  
  19. $mesg = "--" . $boundary . "\n";
  20. $mesg = $mesg . "Content-Type: text/plain; charset=\"iso-8859-2\"\n\n";
  21. $mesg = $mesg
  22.  
  23. .$numer = "Numer zlecenia: $numer" ." "
  24. .$data1 = "Data: $data1" ."\n"
  25. .$zleceniodawca = "Zleceniodawca: $zleceniodawca" ."\n"
  26. .$z_jezyka = "Tlumaczenie z jezyka: $z_jezyka" ." "
  27. .$na_jezyk = "na jezyk: $na_jezyk" ."\n"
  28. .$dane = "Dane do rachunku: $dane" ."\n"
  29. .$telefon = "Telefon: $telefon" ."\n"
  30. .$uwagi = "Uwagi: $uwagi" ."\n"
  31. .$www = "Strona www: $www" ."\n"
  32. .$email = "E-MAIL: $email" ."\n"
  33. .$data = "Wysłano dnia: $data" ."\n";
  34.  
  35. // plik1
  36.  
  37. $mesg = $mesg . "--" . $boundary . "\n";
  38. $mesg = $mesg . "Content-type: " . $filename1_type . "; name=\"$filename1_name\";\n";
  39. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  40. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename1_name\"\n\n";
  41. $mesg = $mesg . fileopenanddecode($filename1) . "\n";
  42. $mesg = $mesg . "--" . $boundary . "\n";
  43.  
  44. // plik2
  45.  
  46. $mesg = $mesg . "--" . $boundary . "\n";
  47. $mesg = $mesg . "Content-type: " . $filename2_type . "; name=\"$filename2_name\";\n";
  48. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  49. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename2_name\"\n\n";
  50. $mesg = $mesg . fileopenanddecode($filename2) . "\n";
  51. $mesg = $mesg . "--" . $boundary . "\n";
  52.  
  53. // plik3
  54.  
  55. $mesg = $mesg . "--" . $boundary . "\n";
  56. $mesg = $mesg . "Content-type: " . $filename3_type . "; name=\"$filename3_name\";\n";
  57. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  58. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename3_name\"\n\n";
  59. $mesg = $mesg . fileopenanddecode($filename3) . "\n";
  60. $mesg = $mesg . "--" . $boundary . "\n";
  61.  
  62. // plik4
  63.  
  64. $mesg = $mesg . "--" . $boundary . "\n";
  65. $mesg = $mesg . "Content-type: " . $filename4_type . "; name=\"$filename4_name\";\n";
  66. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  67. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename4_name\"\n\n";
  68. $mesg = $mesg . fileopenanddecode($filename4) . "\n";
  69. $mesg = $mesg . "--" . $boundary . "\n";
  70.  
  71. // plik5
  72.  
  73. $mesg = $mesg . "--" . $boundary . "\n";
  74. $mesg = $mesg . "Content-type: " . $filename5_type . "; name=\"$filename5_name\";\n";
  75. $mesg = $mesg . "Content-Transfer-Encoding: base64\n";
  76. $mesg = $mesg . "Content-disposition: attachment; filename= \"$filename5_name\"\n\n";
  77. $mesg = $mesg . fileopenanddecode($filename5) . "\n";
  78. $mesg = $mesg . "--" . $boundary . "-- \n";
  79.  
  80.  
  81.  
  82. function fileopenanddecode($file) {
  83. if (is_readable($file)) {
  84. $fd = fopen($file, "r");
  85. $plik = fread($fd, filesize($file));
  86. $encoded = chunk_split(base64_encode($plik));
  87. fclose($fd);
  88. }
  89. return $encoded;
  90. }
  91.  
  92. mail("mojmail@wp.pl", "ZLECENIE ON LINE", $mesg , $head);
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. ?>
  100.  
  101. <html>
  102.  
  103. <head>
  104. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  105. <meta http-equiv="Content-Language" content="pl">
  106. <link rel="Shortcut icon" href="images/ikonka.ico" />
  107. <title>Zlecenie</title>
  108. </head>
  109.  
  110. <body bgcolor="#9D826D">
  111.  
  112. <p align="left">
  113. <p></p>
  114. <p></p>
  115. <font face="Arial" style="font-size: 14px" color="#FFFFFF"><b>Dziękuję, Twoje dane zostały przesłane!</b></font>
  116. <p></p>
  117. <button name="B3" onclick="java script:history.back();">Kolejne zlecenie
  118. </button></p>
  119. </body>
  120.  
  121. </html>


Ten post edytował marjaan 15.10.2009, 03:04:07
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.04.2024 - 05:35