Advertisement
Guest User

kod na formularz - pecetowicz

a guest
Feb 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.60 KB | None | 0 0
  1. <?php
  2. $twojemail = "xxx@o2.pl"; //na jaki adres ma zostać wysłana treść z formularza
  3. $blad=0;
  4. if (isset($_POST['submit'])) {
  5.            // filtrowanie treści wprowadzonych przez użytkownika
  6.            $name = htmlspecialchars(stripslashes(strip_tags(trim($_POST["name"]))), ENT_QUOTES);
  7.            $email = htmlspecialchars(stripslashes(strip_tags(trim($_POST["email"]))), ENT_QUOTES);
  8.            $message = htmlspecialchars(stripslashes(strip_tags(trim($_POST["message"]))), ENT_QUOTES);
  9.             $temat = 'Kontakt';
  10.             $ip = $_SERVER['REMOTE_ADDR'];
  11.            // sprawdzamy czy wszystkie pola zostały wypełnione
  12.            if (!$name) {
  13.                $blad++;
  14.                echo 'Prosimy wpisać nick.';
  15.            }
  16.            if (!$email) {
  17.                $blad++;
  18.                echo 'Prosimy wpisać adres E-mail.';
  19.            }
  20.            if (!$message) {
  21.                $blad++;
  22.                echo 'Prosimy wpisać treść wiadomości.';
  23.            }
  24.            // jeżeli nie ma błędu, to wiadomość e-mail zostaje wysłana
  25.            if ($blad == 0) {
  26.                // niezbędne nagłówki do wyświetlania wiadomości HTML
  27.                $naglowki = "MIME-Version: 1.0" . "\r\n";
  28.                $naglowki .= "Content-type:text/html;charset=utf-8" . "\r\n";
  29.                // opcjonalne nagłówki
  30.                $naglowki .= 'From: <'.$email.'>' . "\r\n";
  31.                 $naglowki .= 'Cc: <'.$twojemail.'>' . "\r\n";
  32.                 // całkowita treść wiadomości
  33.                 $message = nl2br($message);
  34.                 $wiadomosc = <<< KONIEC
  35.                <html>
  36.                     <strong>Imie:</strong> $name<br />
  37.                     <strong>E-mail:</strong> $email<br />
  38.                     <strong>IP:</strong> $ip <br />
  39.                     <strong>Wiadomość:</strong><br /> $message
  40.                 </html>
  41. KONIEC;
  42.                 // wysyłanie wiadomości e-mail
  43.                 $wynik = mail('<'.$twojemail.'>', $temat, $wiadomosc, $naglowki);
  44.                 // komunikat potwierdzający wysłanie wiadomości bądź nie
  45.                 if ($wynik) {
  46.                     echo 'Wiadomość została wysłana.';
  47.                 } else {
  48.                     echo 'Wystąpił bład.';
  49.                 }
  50.             }
  51.         }
  52. ?>
  53. <div class="row">
  54.                   <form method="post" name="contactform" action="kontakt.php">
  55.                       <div class="col-sm-6">
  56.                         <div class="form-group">
  57.                         <font size="2">Imie<br />
  58.                           <input type="text" name="name" id="name" class="form-control">
  59.                          </div>
  60.                         </div>
  61.                        <div class="col-sm-6">
  62.                         <div class="form-group">
  63.                         E-mail<br />
  64.                          <input type="text" name="email" id="email" class="form-control">
  65.                          </div>
  66.                         </div>
  67.                        <div class="col-sm-12">
  68.                         <div class="textarea-message form-group">
  69.                         Treść wiadomości</font><br />
  70.                           <textarea name="message" id="message" class="textarea-message form-control" rows="7" cols="27"></textarea>
  71.                           </div>
  72.                          </div>
  73.                     <div class="text-center">    
  74.                        <button type="submit" name="submit" value="Send message" class="button button-style button-style-dark button-style-icon fa fa-long-arrow-right text-center">Wyślij wiadomość</button>
  75.                      </div>
  76.                   </form>
  77.                 </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement