Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] mail()
grzegorzko90
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 6.12.2008
Skąd: Małopolska

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


Witam. Stworzyłem formularz, którego zadaniem jest wysłanie zamówienia... Wszystko działa śmiga tylko jest jeden problem nie wiem jak zrobić ,żeby można było wysłać załącznik. Czytałem trochę na różnych stronach lecz nie znalazłem nic konkretnego (czyt. zrozumiałego dla mnie)

Załączam kod formularza i pliku php

  1. <form action="zam.php" method="post">
  2. <lable>Imię:*<br /> <input type="text" value="" name="imie" /></lable><br />
  3. <lable>Nazwisko:*<br /> <input type="text" value="" name="nazwisko" /></lable><br />
  4. <lable>E-mail:*<br /> <input type="text" value="" name="mail" /></lable><br />
  5. <lable>Firma: <br /> <input type="text" value="" name="firma" /></lable><br />
  6. <label>Opis zamówienia:* <br /> <input style="height: 150px ; width: 350px;" type="text" value="" name="opis" /></label><br />
  7. <lable>Plik (cdr,jpg,gif,pdf,png): <br /> <input type="file" value="" name="plik" /></lable><br /><br />
  8. <input type="submit" value="wyślij" />
  9. </form>


  1. <?php
  2. $imie=$_POST['imie'];
  3. $nazwisko=$_POST['nazwisko'];
  4. $mail=$_POST['mail'];
  5. $fimra=$_POST['firma'];
  6. $opis=$_POST['opis'];
  7. $plik=$_POST['plik'];
  8. $adresat="cos@gmail.com";
  9. $temat="Zamówienie online";
  10. $glowna_tresc=" Nadawca: " . $imie . " " . $nazwisko . " Email: " . $mail . " Treść: " . $opis;
  11.  
  12. if ($imie=="" OR $nazwisko=="" OR $mail=="" OR $opis=="")
  13. {
  14. exit ('wypełnij pola wymagane !');
  15. }
  16. else
  17. {
  18. $wyslij=mail($adresat, $temat, $glowna_tresc);
  19. if ($wyslij)
  20. {
  21. echo "<center><strong>Zamówienie zostało złożone !, Dziękujemy</strong></center>";
  22. }
  23. else
  24. {
  25. exit ('<center>Błąd podczas składania zamówienia, sprubj później</center>');
  26. }
  27. }
  28. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
oi.
post
Post #2





Grupa: Zarejestrowani
Postów: 145
Pomógł: 1
Dołączył: 12.07.2006

Ostrzeżenie: (10%)
X----


Ja robię z podanym przez Ciebie przykładem:
  1. <?php
  2. $to = "...@...pl";
  3. $email = $_POST['email'];
  4. $name = $_POST['name'];
  5. $subject = "temat wiadomosci";
  6. $comment = $_POST['message'];
  7.  
  8. $To = strip_tags($to);
  9. $TextMessage =strip_tags(nl2br($comment),"<br>");
  10. $HTMLMessage =nl2br($comment);
  11. $FromName =strip_tags($name);
  12. $FromEmail =strip_tags($email);
  13. $Subject =strip_tags($subject);
  14.  
  15. $boundary1 =rand(0,9)."-"
  16. .rand(10000000000,9999999999)."-"
  17. .rand(10000000000,9999999999)."=:"
  18. .rand(10000,99999);
  19. $boundary2 =rand(0,9)."-".rand(10000000000,9999999999)."-"
  20. .rand(10000000000,9999999999)."=:"
  21. .rand(10000,99999);
  22.  
  23.  
  24. for($i=0; $i < count($_FILES['fileatt']['name']); $i++){
  25. if(is_uploaded_file($_FILES['fileatt']['tmp_name'][$i]) &&
  26. !empty($_FILES['fileatt']['size'][$i]) &&
  27. !empty($_FILES['fileatt']['name'][$i])){
  28.  
  29. $attach ='yes';
  30. $end ='';
  31.  
  32. $handle =fopen($_FILES['fileatt']['tmp_name'][$i], 'rb');
  33. $f_contents =fread($handle, $_FILES['fileatt']['size'][$i]);
  34. $attachment[]=chunk_split(base64_encode($f_contents));
  35. fclose($handle);
  36.  
  37. $ftype[] =$_FILES['fileatt']['type'][$i];
  38. $fname[] =$_FILES['fileatt']['name'][$i];
  39. }
  40. }
  41.  
  42. /***************************************************************
  43.  Creating Email: Headers, BODY
  44.  1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
  45.  ***************************************************************/
  46. #---->Headers Part
  47. $Headers =<<<AKAM
  48. From: $FromName <$FromEmail>
  49. Reply-To: $FromEmail
  50. MIME-Version: 1.0
  51. Content-Type: multipart/alternative;
  52.   boundary="$boundary1"
  53. AKAM;
  54.  
  55. #---->BODY Part
  56. $Body =<<<AKAM
  57. MIME-Version: 1.0
  58. Content-Type: multipart/alternative;
  59.   boundary="$boundary1"
  60.  
  61. This is a multi-part message in MIME format.
  62.  
  63. --$boundary1
  64. Content-Type: text/plain;
  65.   charset="windows-1256"
  66. Content-Transfer-Encoding: quoted-printable
  67.  
  68. $TextMessage
  69. --$boundary1
  70. Content-Type: text/html;
  71.   charset="windows-1256"
  72. Content-Transfer-Encoding: quoted-printable
  73.  
  74. $HTMLMessage
  75.  
  76. --$boundary1--
  77. AKAM;
  78.  
  79. /***************************************************************
  80.  2- HTML Email WIth Multiple Attachment <<----- Attachment ------
  81.  ***************************************************************/
  82.  
  83. if($attach=='yes') {
  84.  
  85. $attachments='';
  86. $Headers =<<<AKAM
  87. From: $FromName <$FromEmail>
  88. Reply-To: $FromEmail
  89. MIME-Version: 1.0
  90. Content-Type: multipart/mixed;
  91.   boundary="$boundary1"
  92. AKAM;
  93.  
  94. for($j=0;$j<count($ftype); $j++){
  95. $attachments.=<<<ATTA
  96. --$boundary1
  97. Content-Type: $ftype[$j];
  98.   name="$fname[$i]"
  99. Content-Transfer-Encoding: base64
  100. Content-Disposition: attachment;
  101.   filename="$fname[$j]"
  102.  
  103. $attachment[$j]
  104.  
  105. ATTA;
  106. }
  107.  
  108. $Body =<<<AKAM
  109. This is a multi-part message in MIME format.
  110.  
  111. --$boundary1
  112. Content-Type: multipart/alternative;
  113.   boundary="$boundary2"
  114.  
  115. --$boundary2
  116. Content-Type: text/plain;
  117.   charset="windows-1256"
  118. Content-Transfer-Encoding: quoted-printable
  119.  
  120. $TextMessage
  121. --$boundary2
  122. Content-Type: text/html;
  123.   charset="windows-1256"
  124. Content-Transfer-Encoding: quoted-printable
  125.  
  126. $HTMLMessage
  127.  
  128. --$boundary2--
  129.  
  130. $attachments
  131. --$boundary1--
  132. AKAM;
  133. }
  134.  
  135. /***************************************************************
  136.  Sending Email
  137.  ***************************************************************/
  138. $ok=mail($To, $Subject, $Body, $Headers);
  139. echo $ok?"<h1> Mail Sent </h1>":"<h1> Mail not SEND</h1>";
  140. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 8.10.2025 - 16:40