Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z formularzem kontaktowym, Nie docierają do mnie wiadomości
senior.pol
post 3.12.2011, 22:16:44
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Witam
Pytanie mam proste. Co mam nie tak w tym skrypcie, że nie docierają do mnie wiadomości?
  1. jQuery(document).ready(function($) {
  2.  
  3. // hide messages
  4. $("#error").hide();
  5. $("#success").hide();
  6.  
  7. // on submit...
  8. $("#contactForm #submit").click(function() {
  9. $("#error").hide();
  10.  
  11. //required:
  12.  
  13. //name
  14. var name = $("input#name").val();
  15. if(name == ""){
  16. $("#error").fadeIn().text("Name required.");
  17. $("input#name").focus();
  18. return false;
  19. }
  20.  
  21. // email
  22. var email = $("input#email").val();
  23. if(email == ""){
  24. $("#error").fadeIn().text("Email required");
  25. $("input#email").focus();
  26. return false;
  27. }
  28.  
  29. // web
  30. var web = $("input#web").val();
  31. if(web == ""){
  32. $("#error").fadeIn().text("Web required");
  33. $("input#web").focus();
  34. return false;
  35. }
  36.  
  37. // comments
  38. var comments = $("#comments").val();
  39.  
  40. // send mail php
  41. var sendMailUrl = $("#sendMailUrl").val();
  42.  
  43. //to, from & subject
  44. var to = $("#to").val();
  45. var from = $("#from").val();
  46. var subject = $("#subject").val();
  47.  
  48. // data string
  49. var dataString = 'name='+ name
  50. + '&email=' + email
  51. + '&web=' + web
  52. + '&comments=' + comments
  53. + '&to=' + to
  54. + '&from=' + from
  55. + '&subject=' + subject;
  56. // ajax
  57. $.ajax({
  58. type:"POST",
  59. url: sendMailUrl,
  60. data: dataString,
  61. success: success()
  62. });
  63. });
  64.  
  65.  
  66. // on success...
  67. function success(){
  68. $("#success").fadeIn();
  69. $("#contactForm").fadeOut();
  70. }
  71.  
  72. return false;
  73. });

i
  1. <script type="text/javascript" src="js/form-validation.js"></script>
  2. <form id="contactForm" action="#" method="post">
  3. <div>
  4. <label>Imię i nazwisko</label>
  5. <input name="name" id="name" type="text" class="form-poshytip" title="Wpisz pełne dane" />
  6. </div>
  7. <div>
  8. <label>Email</label>
  9. <input name="email" id="email" type="text" class="form-poshytip" title="Twój adres email" />
  10. </div>
  11. <div>
  12. <label>Temat</label>
  13. <input name="web" id="web" type="text" class="form-poshytip" title="Temat wiadomości" />
  14. </div>
  15. <div>
  16. <label>Wiadomość</label>
  17. <textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Tekst wiadomości"></textarea>
  18. </div>
  19.  
  20. <!-- send mail configuration -->
  21. <input type="hidden" value="xxxx@xxxxxxxxxxx" name="to" id="to" />
  22. <input type="hidden" value="xxxx@xxxxxxxxxxx" name="from" id="from" />
  23. <input type="hidden" value="From torn wordpress online" name="subject" id="subject" />
  24. <input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
  25. <!-- ENDS send mail configuration -->
  26.  
  27. <p><input type="button" value="WYŚLIJ" name="submit" id="submit" /></p>
  28. <p id="error" class="warning">Message</p>
  29. </form>
  30. <p id="success" class="success">Wiadomość wysłana !</p>

  1. <?php
  2.  
  3. //vars
  4. $subject = $_POST['subject'];
  5. $to = explode(',', $_POST['to'] );
  6.  
  7. $from = $_POST['email'];
  8.  
  9. //data
  10. $msg = "NAME: " .$_POST['name'] ."<br>\n";
  11. $msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
  12. $msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
  13. $msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
  14.  
  15. //Headers
  16. $headers = "MIME-Version: 1.0\r\n";
  17. $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  18. $headers .= "From: <".$from. ">" ;
  19.  
  20.  
  21. //send for each mail
  22. foreach($to as $mail){
  23. mail($mail, $subject, $msg, $headers);
  24. }
  25.  
  26. ?>

Z góry dziękuję za odpowiedź smile.gif

Ten post edytował senior.pol 3.12.2011, 22:37:53
Go to the top of the page
+Quote Post
qrooel
post 3.12.2011, 22:34:12
Post #2





Grupa: Zarejestrowani
Postów: 306
Pomógł: 42
Dołączył: 25.03.2010
Skąd: Kraków

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


Zapomniałeś jeszcze podać pliku PHP, który zajmuje się wysyłką.


--------------------
Strony WWW: http://arscreo.pl
Go to the top of the page
+Quote Post
senior.pol
post 3.12.2011, 22:38:17
Post #3





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Sorry ,zapomniałem. Już dodane smile.gif
Go to the top of the page
+Quote Post
markonix
post 3.12.2011, 23:12:24
Post #4





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Wrzuć to na żywo, założę się to jakaś bzdura typu brak zainicjowanej biblioteki jQuery.
Czy badałeś skrypt np. FireBugiem? Czy ajax wywołuje funkcje success? Czy zauważyłeś, że to wysyła kilka maili (grupa odbiorców)? Czy sam skrypt PHP działa?


--------------------
Go to the top of the page
+Quote Post
senior.pol
post 4.12.2011, 17:32:28
Post #5





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


To jak to zrobić ,aby nie wysyłało do kilku odbiorców, tylko do mnie?
Go to the top of the page
+Quote Post
markonix
post 4.12.2011, 17:59:31
Post #6





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Teraz rozdziela kolejne maile za pomocą funkcji explode, a następnie wysyła kolejno maile pętlą foreach - usuń te rzeczy i powinno wysyłać jednego. Ogólnie jeżeli wpisywałeś jednego maila to nie miało to zbytnio znaczenia (po prostu pętla raz powinna się wykonać).


--------------------
Go to the top of the page
+Quote Post
senior.pol
post 5.12.2011, 15:25:13
Post #7





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Problem był banalny i prosty. Testowałem sobie ten formularz na serwerze yoyo.pl, który nie obsługuje funkcji mail. Sprawdziłem u siebie na serwerze i działa ok. Dzięki za fatygę
Pozdrawiam

Ten post edytował senior.pol 5.12.2011, 15:56:44
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:41