Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> problem z załącznikiem i mailem, wysyłanie maila z php z załącznikiem
niko
post 4.07.2005, 01:06:31
Post #1





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 2.06.2005

Ostrzeżenie: (30%)
XX---


Wiem że było to już poruszane ale niestety nie moge sobie z tym poradzić nadal mi wywala błędy sad.gif mam taki skrypt :

  1. <?
  2. if ($action == &#092;"send\")
  3. {
  4. $header = &#092;"From: \" . $from . \"n\";
  5. if ($attachement != &#092;"none\")
  6. {
  7. // Get attachement type
  8. $type = $HTTP_POST_FILES[attachement][type];
  9. if (($type == &#092;"text/plain\") || ($type == \"text/html\"))
  10. $encoding = &#092;"8bit\";
  11. else
  12. $encoding = &#092;"base64\";
  13.  
  14. // Get attachement content
  15. /* $fp = @fopen($HTTP_POST_FILES[attachement][tmp_name],\"r\");
  16. if (!$fp) {
  17. print \"Could not open attachment for reading...<br>n\";
  18. print \"Exiting script!<br><br>\";
  19. print \"No mail has been sent!\";
  20. exit;
  21. }
  22. */ $file_content = fread($fp,filesize($HTTP_POST_FILES[attachement][tmp_name]));
  23.  
  24. // if encoding is base64 ... encode it
  25. if ($encoding == &#092;"base64\")
  26. $file_content = chunk_split(base64_encode($file_content));
  27.  
  28. // create a unqiue boundary
  29. $boundary = strtoupper(md5(uniqid(time())));
  30.  
  31. // create the message header...
  32. $header .= &#092;"MIME-version: 1.0n\";
  33. $header .= &#092;"Content-Type: multipart/mixed;n\";
  34. $header .= &#092;"tboundary= \" . $boundary . \"nn\";
  35.  
  36. $header .= &#092;"This is a multi-part message in MIME format.nn\";
  37.  
  38. // create the message body in the header
  39. $header .= &#092;"--\" . $boundary . \"n\";
  40. $header .= &#092;"Content-Type: \" . $ct . \";n\";
  41. $header .= &#092;"tcharset=\"iso-8859-1\"n\";
  42. $header .= &#092;"Content-Transfer-Encoding: quoted-printablenn\";
  43.  
  44. // actual message
  45. $header .= $body . &#092;"nn\";
  46.  
  47. // now for the attachement
  48. $header .= &#092;"--\" . $boundary . \"n\";
  49. $header .= &#092;"Content-Type: \" . $type . \"n\";
  50. $header .= &#092;"Content-Transfer-Encoding: \" . $encoding . \"n\";
  51. $header .= &#092;"Content-Disposition: attachment; filename=\"\" . $HTTP_POST_FILES[attachement][name] . \"\"nn\";
  52.  
  53. // actual attachement
  54. $header .= $file_content . &#092;"nn\";
  55. $header .= &#092;"--\" . $boundary . \"--\";
  56. }
  57. else // if there is no attachement...
  58. {
  59. $header .= &#092;"Content-Type: \" . $ct . \";n\";
  60. $header .= &#092;"tcharset=\"iso-8859-1\"n\";
  61. $header .= &#092;"Content-Transfer-Encoding: quoted-printablenn\";
  62.  
  63. // actual message
  64. $header .= $body . &#092;"nn\";
  65. }
  66. if (@mail($to,$subject,&#092;"\",$header))
  67. print &#092;"Mail sent!\";
  68. else
  69. print &#092;"Error sending email!\";
  70.  
  71. }
  72. else
  73. {
  74. ?>
  75.  
  76. <html>
  77.  
  78. <head>
  79. <title>Mail Attachement</title>
  80. </head>
  81.  
  82. <body bgcolor=\"#FFFFFF\">
  83.  
  84. <center>
  85. <form enctype=\"multipart/form-data\" action=\"1.php\" method=\"POST\">
  86. <input type=\"hidden\" name=\"action\" value=\"send\">
  87. <table width=\"500\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
  88. <tr>
  89. <td width=\"150\" align=\"left\" valign=\"center\">
  90. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  91. To:
  92. </font>
  93. </td>
  94. <td width=\"350\" align=\"left\" valign=\"center\">
  95. <input type=\"text\" size=\"40\" name=\"to\">
  96. </td>
  97. </tr>
  98. <tr>
  99. <td width=\"150\" align=\"left\" valign=\"center\">
  100. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  101. From:
  102. </font>
  103. </td>
  104. <td width=\"350\" align=\"left\" valign=\"center\">
  105. <input type=\"text\" size=\"40\" name=\"from\">
  106. </td>
  107. </tr>
  108. <tr>
  109. <td width=\"150\" align=\"left\" valign=\"center\">
  110. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  111. Subject:
  112. </font>
  113. </td>
  114. <td width=\"350\" align=\"left\" valign=\"center\">
  115. <input type=\"text\" size=\"40\" name=\"subject\">
  116. </td>
  117. </tr>
  118. <tr>
  119. <td width=\"150\" align=\"left\" valign=\"center\">
  120. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  121. Content type:
  122. </font>
  123. </td>
  124. <td width=\"350\" align=\"left\" valign=\"center\">
  125. <select name=\"ct\">
  126. <option value=\"text/plain\">Plaintext</option>
  127. <option value=\"text/html\">HTML mail</option>
  128. </select>
  129. </td>
  130. </tr>
  131. <tr>
  132. <td width=\"150\" align=\"left\" valign=\"top\">
  133. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  134. Message body:
  135. </font>
  136. </td>
  137. <td width=\"350\" align=\"left\" valign=\"top\">
  138. <textarea rows=\"8\" cols=\"38\" name=\"body\"></textarea>
  139. </td>
  140. </tr>
  141. <tr>
  142. <td width=\"150\" align=\"left\" valign=\"center\">
  143. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  144. Attachement:
  145. </font>
  146. </td>
  147. <td width=\"350\" align=\"left\" valign=\"center\">
  148. <input type=\"file\" name=\"attachement\">
  149. </td>
  150. </tr>
  151. <tr>
  152. <td width=\"150\" align=\"left\" valign=\"center\">
  153. <font face=\"Verdana,Tahoma,Arial,Helvetica\" size=\"2\" color=\"#000000\">
  154. &nbsp;
  155. </font>
  156. </td>
  157. <td width=\"350\" align=\"left\" valign=\"center\">
  158. <input type=\"submit\" value=\"Send\">
  159. </td>
  160. </tr>
  161. </table>
  162. </center>
  163. </form>
  164. </body></html>
  165. <?
  166. }
  167. ?>


niestety wywala mi błąd:

Warning: fread(): supplied argument is not a valid stream resource in /home/xxxc/public_html/test/1.php on line 22
Mail sent!

mail dochodzi z załącznikiem ale nie moge go otworzyć sad.gif(
wydaje się być uszkodzony sad.gif
i jak zrobić by wyświetlał polskie znaczki w treści wiadomości ?

proszę o pomoc smile.gif
Go to the top of the page
+Quote Post
nospor
post 4.07.2005, 08:12:53
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




do fread zapodajesz jako parametr $fp. $fp = fopen(..... Sęk w tym, że u ciebie ta inicjalizacja $fp jest wykomentowana, więc się nie dziw że nie dziala.

pozdro


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
niko
post 4.07.2005, 11:09:34
Post #3





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 2.06.2005

Ostrzeżenie: (30%)
XX---


dzięki Nospor smile.gif


a jak zrobić tam żeby były polskie znaczki w treści wysyłanej wiadomości ?

aha no i jak np mozna ograniczyć wielkość załącznika np do 1MB ?
Go to the top of the page
+Quote Post
nospor
post 4.07.2005, 11:12:39
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




w header ustawiasz iso-8859-1. Ustaw se iso-8859-2 lub utf-8 w zależnosci jak kodujesz i bedziesz mial polskie znaczki.

rozmiar określasz w max. rozmiarze pliku uplodowanego w php.ini. Bo przed wyslaniem ty uploud robisz, tak?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

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: 19.07.2025 - 09:02