Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Formularz kontaktowy - gdzie błąd?
interlaw
post 29.05.2016, 02:19:39
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.05.2016

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


Koleżanki, Koledzy!

Pomóżcie mi proszę odnaleźć błąd w skrypcie, formularz nie działa (wiadomości nie dochodzą).

HTML:

  1. <div class="col-md-5 col-sm-5">
  2.  
  3. <div class="vertical-registration-form">
  4. <div class="colored-line">
  5. </div>
  6. <h3>bezpłatny kontakt</h3>
  7. <form class="registration-form" id="register" role="form">
  8. <input class="form-control input-box" id="name" type="text" name="name" placeholder="Imię i nazwisko">
  9. <input class="form-control input-box" id="email" type="email" name="email" placeholder="E-mail">
  10. <input class="form-control input-box" id="phone-number" type="text" name="phone-number" placeholder="Numer telefonu">
  11. <button class="btn standard-button" type="submit" id="submit" name="submit">Wyślij</button>
  12. </form>
  13. </div>
  14. </div>
  15. </div>
  16.  
  17. </div>
  18.  
  19. </div>


PHP:

  1. <?php
  2. // Email Submit
  3. // Note: filter_var() requires PHP >= 5.2.0
  4. if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  5.  
  6. // detect & prevent header injections
  7. $test = "/(content-type|bcc:|cc:|to:)/i";
  8. foreach ( $_POST as $key => $val ) {
  9. if ( preg_match( $test, $val ) ) {
  10. }
  11. }
  12.  
  13. $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
  14. 'Reply-To: ' . $_POST["email"] . "\r\n" .
  15. 'X-Mailer: PHP/' . phpversion();
  16.  
  17. //
  18. mail( "MÓJ.ADRES.MAILOWY", $_POST['subject'], $_POST['message'], $headers );
  19.  
  20. // ^
  21. // Replace with your email
  22. }
  23. ?>
Go to the top of the page
+Quote Post
CuteOne
post 29.05.2016, 12:54:17
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Jeżeli wrzuciłeś nam cały formularz, to brakuje w nim pól, które sprawdzasz w skrypcie PHP. Zobacz czy w ogóle przejdziesz walidację
  1. if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  2. die('a');
  3. }


Ten post edytował CuteOne 29.05.2016, 12:54:48
Go to the top of the page
+Quote Post
interlaw
post 29.05.2016, 13:04:00
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.05.2016

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


Cytowany przez Ciebie kod jest w skrypcie PHP, mimo to wiadomości nie zostają wysłane sad.gif
Go to the top of the page
+Quote Post
CuteOne
post 29.05.2016, 13:40:41
Post #4





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Po dodaniu mojego kodu, i wysłaniu formularza, na ekranie pokazuje się "A"?
Go to the top of the page
+Quote Post
interlaw
post 29.05.2016, 15:52:18
Post #5





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.05.2016

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


Dobra. Mój błąd, tutaj jest kod z dwóch różnych skryptów.
Poniżej umieszczam właściwe:

HTML:
  1. <!-- EXPANDED CONTACT FORM -->
  2. <div class="expanded-contact-form">
  3.  
  4. <!-- FORM -->
  5. <form class="contact-form" id="contact" role="form">
  6.  
  7. <!-- IF MAIL SENT SUCCESSFULLY -->
  8. <h6 class="success">
  9. <span class="olored-text icon_check"></span> Your message has been sent successfully. </h6>
  10.  
  11. <!-- IF MAIL SENDING UNSUCCESSFULL -->
  12. <h6 class="error">
  13. <span class="colored-text icon_error-circle_alt"></span> E-mail must be valid and message must be longer than 1 character. </h6>
  14.  
  15. <div class="field-wrapper col-md-6">
  16. <input class="form-control input-box" id="cf-name" type="text" name="cf-name" placeholder="Imię i nazwisko">
  17. </div>
  18.  
  19. <div class="field-wrapper col-md-6">
  20. <input class="form-control input-box" id="cf-email" type="email" name="cf-email" placeholder="E-mail">
  21. </div>
  22.  
  23. <div class="field-wrapper col-md-12">
  24. <input class="form-control input-box" id="cf-subject" type="text" name="cf-subject" placeholder="Temat">
  25. </div>
  26.  
  27. <div class="field-wrapper col-md-12">
  28. <textarea class="form-control textarea-box" id="cf-message" rows="7" name="cf-message" placeholder="Wiadomość"></textarea>
  29. </div>
  30.  
  31. <button class="btn standard-button" type="submit" id="cf-submit" name="submit" data-style="expand-left">Wyślij</button>
  32. </form>
  33. <!-- /END FORM -->
  34. </div>
  35.  
  36. </div>
  37. </div>
  38.  
  39. </div>
  40.  
  41. </section>


PHP (sendmail.php):

  1. <?php
  2. // Email Submit
  3. // Note: filter_var() requires PHP >= 5.2.0
  4. if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  5. die('a');
  6. }
  7. // detect & prevent header injections
  8. $test = "/(content-type|bcc:|cc:|to:)/i";
  9. foreach ( $_POST as $key => $val ) {
  10. if ( preg_match( $test, $val ) ) {
  11. }
  12. }
  13.  
  14. $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
  15. 'Reply-To: ' . $_POST["email"] . "\r\n" .
  16. 'X-Mailer: PHP/' . phpversion();
  17.  
  18. //
  19. mail( "moj@mail.pl", $_POST['subject'], $_POST['message'], $headers );
  20.  
  21. // ^
  22. // Replace with your email
  23. }
  24. ?>


Jak na moje oko brakuje odwołanie do pliku sendmail.php, natomiast polecnie antion nie rozwiązuje problemu. Mogę liczyć ma Wasze podpowiedzi? ]

Ten post edytował interlaw 29.05.2016, 15:56:14
Go to the top of the page
+Quote Post
CuteOne
post 29.05.2016, 15:56:29
Post #6





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


@edit
- cofnij zmiany, o które prosiłem
- porównaj nazwy pól formularza, a tym co sprawdzasz w skrypcie (np. isset($_POST['name'])).
- popraw je i daj znać czy zadziałało

Ten post edytował CuteOne 29.05.2016, 16:00:24
Go to the top of the page
+Quote Post
interlaw
post 29.05.2016, 16:27:05
Post #7





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.05.2016

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


Nie działa -.-"
Wyświetla, że wiadomość została wysłana, natomiast na skrzynce nic się nie pojawia. Mail w skrypcie jest poprawny. Ehh...
Go to the top of the page
+Quote Post
viking
post 29.05.2016, 18:49:50
Post #8





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Jesli wysyłasz z komputera domowego może być odrzucany bo nie masz pewnie żadnej konfiguracji typu SPF, DKIM. Spróbuj wysłać przez smtp. Poza tym filtruj jakoś te dane z POST.


--------------------
Go to the top of the page
+Quote Post
LowiczakPL
post 29.05.2016, 20:18:38
Post #9





Grupa: Zarejestrowani
Postów: 531
Pomógł: 55
Dołączył: 3.01.2016
Skąd: Łowicz

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


Czy to jest Twój serwer?
Czy wysyłałeś już e-maile za pomocą tej funkcji mail?

ja u siebie na serwerze wyłączyłem mail = funkcja jest przezroczysta = nic nie robi i nie zwraca błędów,

maile można wysyłać tylko za pomocą SMTP

odpal sobie szybki test czy w ogóle mail Ci działa

  1.  
  2. <?php
  3. $message = "Line 1\r\nLine 2\r\nLine 3";
  4. $message = wordwrap($message, 70, "\r\n");
  5. mail('twoj@email.pl', 'My Subject', $message);
  6. ?>
  7.  


Ten post edytował LowiczakPL 29.05.2016, 20:20:44


--------------------
Szukam zleceń Symfony, Laravel, Back-End, Front-End, PHP, MySQL ...
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: 18.04.2024 - 01:03