Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP]Formularz contact.php nie działa
Forum PHP.pl > Forum > Przedszkole
4teista
Witam,

jestem totalnym laikiem i nie potrafię znaleźć błędu w tym formularzu
byłby ktoś skłonny rzucić na to okiem?
(sprawdzałem serwer na innym skrypcie tego typu (html + php) i PHP działa prawidłowo)

Dziękuję i pozdrawiam:
4teista

[html][/html]
</div>
<div class="col-md-6 sep-top-xs wow bounceInRight" data-wow-delay="0.9s">
<div class="contact-form">
<div id="successMessage" style="display:none" class="alert alert-success text-center">
<p><i class="fa fa-check-circle fa-2x"></i></p>
<p>Dziękuję za wysłanie wiadomości! Postaram się odpisać jak najszybciej.</p>
</div>
<div id="failureMessage" style="display:none" class="alert alert-danger text-center">
<p><i class="fa fa-times-circle fa-2x"></i></p>
<p>Wystąpił problem podczas wysyłania wiadomości. Spróbuj ponownie.</p>
</div>
<div id="incompleteMessage" style="display:none" class="alert alert-warning text-center">
<p><i class="fa fa-exclamation-triangle fa-2x"></i></p>
<p>Wypełnij wszystkie pola formularza przed wysłaniem wiadomości.</p>
</div>
<form id="contactForm" action="php/contact.php" method="post" class="validate">
<div class="form-group sep-top-xs">
<label for="contactFormName" class="upper">Imię i Nazwisko</label>
<input id="contactFormName" type="text" placeholder="Wpisz imię i nazwisko" name="name" class="form-control input-lg required">
</div>
<div class="form-group sep-top-xs">
<label for="contactFormPhone" class="upper">Telefon</label>
<input id="contactFormPhone" type="text" placeholder="Wpisz numer telefonu" name="phone" class="form-control input-lg required">
</div>
<div class="form-group sep-top-xs">
<label for="contactFormEmail" class="upper">Email</label>
<input id="contactFormEmail" type="email" placeholder="Wpisz swój email" name="email" class="form-control input-lg required email">
</div>
<div class="form-group sep-top-xs">
<label for="contactFormComment" class="upper">Twoje pytanie</label>
<textarea id="contactFormComment" placeholder="Wpisz swoje pytanie" rows="9" name="comment" class="form-control input-lg required"></textarea>
</div>
<div class="form-group sep-top-xs">
<button type="submit" data-wow-delay="1.1s" class="btn btn-primary btn-lg wow bounceInRight"><i class="fa fa-paper-plane"></i> Wyślij wiadomość</button>
</div>
<!--input#subject.form-control.input-lg.required(type='text', placeholder='Subject of your message', name='subject')
-->
</form>
<div class="hidden"></div>
</div>
</div>
</div>
</div>
</section>

[php][/php]
<?php

header('Access-Control-Allow-Headers: x-requested-with');
header('Access-Control-Allow-Origin: *');

// Define constants. Put your desired values here.
define( 'RECIPIENT_NAME', '4teista' );
define( 'RECIPIENT_EMAIL', '4teista@domena.pl' );
define( 'EMAIL_SUBJECT', 'Wiadomość ze strony www.domena.pl' );

// Read and sanitize the form values
$status = false;
//$xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
$xhr = isset( $_POST['ajax'] )
? true
: false;
$senderName = isset( $_POST['senderName'] )
? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", '', $_POST['senderName'] )
: '';
$senderEmail = isset( $_POST['senderEmail'] )
? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", '', $_POST['senderEmail'] )
: '';
$subject = isset( $_POST['subject'] )
? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", '', $_POST['subject'] )
: EMAIL_SUBJECT;
$comment = isset( $_POST['comment'] )
? nl2br(strip_tags($_POST['comment']))
: '';
$phone = isset( $_POST['phone'] )
? strip_tags($_POST['phone'])
: '';
$company = isset( $_POST['company'] )
? strip_tags($_POST['company'])
: '';

// message body. Modify as needed.
$message_body = <<<ENDOFMESSAGE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<title>{$subject}</title>
</head>
<body>
<h3>{$subject}</h3>
<p>A new message has been sent from your Ottavio website:</p>
<table>
<tr>
<th>Name:</th>
<td>{$senderName}</td>
</tr>
<tr>
<th>Email:</th>
<td>{$senderEmail}</td>
</tr>
<tr>
<th>Phone:</th>
<td>{$phone}</td>
</tr>
<tr>
<th>Company:</th>
<td>{$company}</td>
</tr>
<tr>
<th>Message:</th>
<td>{$comment}</td>
</tr>
</table>
</body>
</html>
ENDOFMESSAGE;

// check the mandatory values: if they exist, send the email
if ( $senderName && $senderEmail && $comment ) :
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";

// Set the required headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-UTF-8' . "\r\n";
$headers .= 'From: ' . $senderName . ' <' . $senderEmail . '>' ."\r\n";
$headers .= 'Reply-To: ' . $senderName . ' <' . $senderEmail . '>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

// If needed, add CC and/or BCC recipients
//$headers .= 'Cc: mail1@example.com' . "\r\n";
//$headers .= 'Bcc: mail2@example.com' . "\r\n";

try {
mail( $recipient, $subject, $message_body, $headers );
$status = 'success';

} catch (Exception $e) {
$status = $e->getMessage();
}

else:
$status = 'error: incomplete data';
endif;

// Return an appropriate response to the browser
if ( $xhr ) :
// AJAX Request
echo $status;

else :
// HTTP Request ?>
<!doctype html>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<p>
<?php
if ( $status == 'success') :
echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>";
else :
echo "<p>There was a problem sending your message. Please try again.</p>";
endif;
?>
</p>
<p>Click your browser's Back button to return to the page.</p>
</body>
</html>
<?php
endif; ?>
Boshi
Wrzuć to w bb bo czytać się nie da... I gdzie jest błąd? jakiś komunikat? masz włączone raportowanie błędów?
4teista
właśnie starałem się wrzucić w bb ale chyba nie umiem

błąd mam:
Wystąpił błąd podczas wysyłania wiadomości. Spróbuj ponownie.

nie wiem gdzie włącza się raportowanie błędów
Boshi
Temat: Jak poprawnie zadac pytanie

Wklej swój kod pomiędzy znaczniki [php][/php] i [html][/html] teraz masz kod wklejony pod tymi znacznikami...
4teista
  1. </div>
  2. <div class="col-md-6 sep-top-xs wow bounceInRight" data-wow-delay="0.9s">
  3. <div class="contact-form">
  4. <div id="successMessage" style="display:none" class="alert alert-success text-center">
  5. <p><i class="fa fa-check-circle fa-2x"></i></p>
  6. <p>Dziękuję za wysłanie wiadomości! Postaram się odpisać jak najszybciej.</p>
  7. </div>
  8. <div id="failureMessage" style="display:none" class="alert alert-danger text-center">
  9. <p><i class="fa fa-times-circle fa-2x"></i></p>
  10. <p>Wystąpił problem podczas wysyłania wiadomości. Spróbuj ponownie.</p>
  11. </div>
  12. <div id="incompleteMessage" style="display:none" class="alert alert-warning text-center">
  13. <p><i class="fa fa-exclamation-triangle fa-2x"></i></p>
  14. <p>Wypełnij wszystkie pola formularza przed wysłaniem wiadomości.</p>
  15. </div>
  16. <form id="contactForm" action="php/contact.php" method="post" class="validate">
  17. <div class="form-group sep-top-xs">
  18. <label for="contactFormName" class="upper">Imię i Nazwisko</label>
  19. <input id="contactFormName" type="text" placeholder="Wpisz imię i nazwisko" name="name" class="form-control input-lg required">
  20. </div>
  21. <div class="form-group sep-top-xs">
  22. <label for="contactFormPhone" class="upper">Telefon</label>
  23. <input id="contactFormPhone" type="text" placeholder="Wpisz numer telefonu" name="phone" class="form-control input-lg required">
  24. </div>
  25. <div class="form-group sep-top-xs">
  26. <label for="contactFormEmail" class="upper">Email</label>
  27. <input id="contactFormEmail" type="email" placeholder="Wpisz swój email" name="email" class="form-control input-lg required email">
  28. </div>
  29. <div class="form-group sep-top-xs">
  30. <label for="contactFormComment" class="upper">Twoje pytanie</label>
  31. <textarea id="contactFormComment" placeholder="Wpisz swoje pytanie" rows="9" name="comment" class="form-control input-lg required"></textarea>
  32. </div>
  33. <div class="form-group sep-top-xs">
  34. <button type="submit" data-wow-delay="1.1s" class="btn btn-primary btn-lg wow bounceInRight"><i class="fa fa-paper-plane"></i> Wyślij wiadomość</button>
  35. </div>
  36. <!--input#subject.form-control.input-lg.required(type='text', placeholder='Subject of your message', name='subject')
  37. -->
  38. </form>
  39. <div class="hidden"></div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </section>


  1. <?php
  2.  
  3. header('Access-Control-Allow-Headers: x-requested-with');
  4. header('Access-Control-Allow-Origin: *');
  5.  
  6. // Define constants. Put your desired values here.
  7. define( 'RECIPIENT_NAME', '4teista' );
  8. define( 'RECIPIENT_EMAIL', '4teista@domena.pl' );
  9. define( 'EMAIL_SUBJECT', 'Wiadomość ze strony www.domena.pl' );
  10.  
  11. // Read and sanitize the form values
  12. $status = false;
  13. //$xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  14. $xhr = isset( $_POST['ajax'] )
  15. ? true
  16. : false;
  17. $senderName = isset( $_POST['senderName'] )
  18. ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", '', $_POST['senderName'] )
  19. : '';
  20. $senderEmail = isset( $_POST['senderEmail'] )
  21. ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", '', $_POST['senderEmail'] )
  22. : '';
  23. $subject = isset( $_POST['subject'] )
  24. ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", '', $_POST['subject'] )
  25. : EMAIL_SUBJECT;
  26. $comment = isset( $_POST['comment'] )
  27. ? nl2br(strip_tags($_POST['comment']))
  28. : '';
  29. $phone = isset( $_POST['phone'] )
  30. ? strip_tags($_POST['phone'])
  31. : '';
  32. $company = isset( $_POST['company'] )
  33. ? strip_tags($_POST['company'])
  34. : '';
  35.  
  36. // message body. Modify as needed.
  37. $message_body = <<<ENDOFMESSAGE
  38. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  39. <html>
  40. <head>
  41.   <meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
  42.   <title>{$subject}</title>
  43. </head>
  44. <body>
  45.   <h3>{$subject}</h3>
  46.   <p>A new message has been sent from your Ottavio website:</p>
  47.   <table>
  48.   <tr>
  49.   <th>Name:</th>
  50.   <td>{$senderName}</td>
  51.   </tr>
  52.   <tr>
  53.   <th>Email:</th>
  54.   <td>{$senderEmail}</td>
  55.   </tr>
  56.   <tr>
  57.   <th>Phone:</th>
  58.   <td>{$phone}</td>
  59.   </tr>
  60.   <tr>
  61.   <th>Company:</th>
  62.   <td>{$company}</td>
  63.   </tr>
  64.   <tr>
  65.   <th>Message:</th>
  66.   <td>{$comment}</td>
  67.   </tr>
  68.   </table>
  69. </body>
  70. </html>
  71. ENDOFMESSAGE;
  72.  
  73. // check the mandatory values: if they exist, send the email
  74. if ( $senderName && $senderEmail && $comment ) :
  75. $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  76.  
  77. // Set the required headers:
  78. $headers = 'MIME-Version: 1.0' . "\r\n";
  79. $headers .= 'Content-type: text/html; charset=iso-UTF-8' . "\r\n";
  80. $headers .= 'From: ' . $senderName . ' <' . $senderEmail . '>' ."\r\n";
  81. $headers .= 'Reply-To: ' . $senderName . ' <' . $senderEmail . '>' . "\r\n";
  82. $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
  83.  
  84. // If needed, add CC and/or BCC recipients
  85. //$headers .= 'Cc: mail1@example.com' . "\r\n";
  86. //$headers .= 'Bcc: mail2@example.com' . "\r\n";
  87.  
  88. try {
  89. mail( $recipient, $subject, $message_body, $headers );
  90. $status = 'success';
  91.  
  92. } catch (Exception $e) {
  93. $status = $e->getMessage();
  94. }
  95.  
  96. else:
  97. $status = 'error: incomplete data';
  98. endif;
  99.  
  100. // Return an appropriate response to the browser
  101. if ( $xhr ) :
  102. // AJAX Request
  103. echo $status;
  104.  
  105. else :
  106. // HTTP Request ?>
  107. <!doctype html>
  108. <html>
  109. <head>
  110. <title>Thanks!</title>
  111. </head>
  112. <body>
  113. <p>
  114. <?php
  115. if ( $status == 'success') :
  116. echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>";
  117. else :
  118. echo "<p>There was a problem sending your message. Please try again.</p>";
  119. endif;
  120. ?>
  121. </p>
  122. <p>Click your browser's Back button to return to the page.</p>
  123. </body>
  124. </html>
  125. <?php
  126. endif; ?>
Boshi
Jak rozumiem, nie Ty pisałeś ten formularz ?

To nie jest błąd.. po prostu w htmlu masz zapisane coś takiego
  1. <p>Wystąpił problem podczas wysyłania wiadomości. Spróbuj ponownie.</p>
i to się wyświetli niezależnie od niczego innego. W ogólę po co te komunikaty są w tym formularzu ? to sie obsługje po stronie serwera w skrypcie php zależnie od spełnionych lub nie warunków.
4teista
To nie ja pisałem
inaczej pewnie nie szukałbym pomocy

to jest kod z szablonu ale nie działa
a support szablonu milczy
Boshi
Daj zrzut ekranu jak to wygląda.
4teista
nie wiem co wkleić

są rubryki z miejscami na imię, mail, telefon, wiadomość

Boshi
I ten komunikat się kiedy ci pojawia? po wciśnięciu jakiegoś przycisku ?
4teista
tak, po wciśnięciu wyślij wiadomość
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.