Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Gorąca prośba o pomoc w formularzu kontaktowym
cachaito
post
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 15.06.2009

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


Witam serdecznie! Mam wielki problem ponieważ muszę wykonać formularz z elementami, których nie potrafię zastosować w praktyce :-/

Otóż potrzebuje jeszcze dwóch dodatków do formularza znalezionego na http://www.egrafik.pl/php-klasa-do-wysylan...e-mail,979.html

Są to:

- weryfikacja e-maila od użytkownika. Na tej samej stronie jest fajny skrypt, tylko, że gdy go wklejam do kodu php, przy próbie wysłania, weryfikuje mi, że podałem błędny adres e-mail razem z komunikatem, że e-mail został wysłany pomyślnie :-)

- jeśli użytkownik nie zaznaczy dwóch checkbox'ów chciałbym, aby formularz upomniał go, że trzeba zaznaczyć te pola.


Znawców php bardzo proszę o pomoc.

A oto kod:

  1. <?php require_once("mailer.php"); ?>
  2.  
  3. <form action="adres_serwera/mailer.php" method="post">
  4. <p>Podaj swoje imię:</p>
  5. <input type="text" name="fromname" /><br />
  6. <p>Podaj swój e-mail:</p>
  7. <input type="text" name="fromemail" /><br />
  8. <p>Na jaki e-mail odpisać?</p>
  9. <input type="text" name="replyemail" /><br />
  10. <p>Temat:</p>
  11. <input type="text" name="subject" /><br />
  12. <p>Treść wiadomości:</p>
  13. <textarea name="message" cols="30" rows="6"></textarea><br />
  14. <p>Do kogo?</p>
  15. <select name="to" size="1">
  16. <optgroup label="Wybierz odbiorcę:">
  17. <option value="adres1@wp.pl">pierwszy adres e-mail</option>
  18. <option value="adres2@gmail.com">drugi adres e-mail</option>
  19. </select><br />
  20. <p>
  21. <input type="checkbox" name="zgoda1" value="1" />
  22. Wyrażam zgodę na przetwarzanie moich danych w formularzu<br />
  23. <input type="checkbox" name="zgoda2" value="1" />
  24. Potwierdzam, że dane wypełniłem prawidłowo.
  25. </p>
  26. <input type="submit" value="Wyślij!" />
  27. </form>


  1. <?php
  2. class MicroMailer{
  3.    var $to         = "";
  4.    var $subject    = "";
  5.    var $message    = "";
  6.    var $fromName   = "";
  7.    var $fromEmail  = "";
  8.    var $replyEmail = "";
  9.    var $header     = "";
  10.    var $type       = "text/plain";
  11.    var $characterSet = "utf-8";
  12.  
  13.  
  14.    function send(){
  15.        $this->createHeader();
  16.        if (@mail($this->to,$this->subject,$this->message,$this->header)){
  17.            return true;
  18.        } else {
  19.            return false;
  20.        }
  21.    }
  22.  
  23. function createHeader(){
  24.        $from   = "From: $this->fromName <$this->fromEmail>r\n";
  25.        $replay = "Reply-To: $this->replyEmailr\n";  
  26.        $params = "MIME-Version: 1.0r\n";
  27.        $params = "Content-type: $this->type; charset=$this->characterSetr\n";
  28.      
  29.        $this->header = $from.$replay.$params;
  30.        return $this->header;
  31.    }
  32.  
  33. }
  34. ?>
  35.  
  36. <?php
  37.      $mailer = new MicroMailer();
  38.      
  39.      $mailer->to         = isset($_POST["to"]) ? $_POST["to"] : "";
  40.      $mailer->fromName   = isset($_POST["fromname"]) ? $_POST["fromname"] : "";
  41.      $mailer->fromEmail  = isset($_POST["fromemail"]) ? $_POST["fromemail"] : "";
  42.      $mailer->replyEmail = isset($_POST["replyemail"]) ? $_POST["replyemail"] : "";
  43.      $mailer->subject    = isset($_POST["subject"]) ? $_POST["subject"] : "";
  44.      $mailer->message    = isset($_POST["message"]) ? $_POST["message"] : "";
  45. if ($mailer->send()) {
  46.        echo "Wiadomość wysłana!";
  47.      } else {
  48.        echo "Błąd podczas wysyłania wiadomości!";
  49.      }
  50. ?>
  51.  
  52. <?php
  53. function  walidacja_email($fromemail) {
  54.  if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", $fromemail))
  55.  {
  56.    echo "wprowadzony adres email jest niepoprawny";
  57.  } else echo "wprowadziłeś poprawny adres email";
  58. }
  59.  
  60. $fromemail = $_POST ["fromemail"];
  61.  
  62. if ($fromemail) walidacja_email($fromemail);
  63. ?>


Ten post edytował cachaito 15.06.2009, 20:08:28
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Wicepsik
post
Post #2





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

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


  1. <?php
  2. if(isset)$_POST['submit']){
  3. if(empty($_POST['fromname'])){
  4.  
  5.    echo 'Nie podałeś swojego imienia';
  6.    
  7. }
  8. elseif(empty($_POST['fromemail']))
  9. {
  10.  
  11.    echo 'Nie podałeś swojego email'a';
  12.    
  13. }
  14. elseif(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", $_POST['fromemail']))
  15. {
  16.  
  17.    echo 'Błędny email';
  18.    
  19. }
  20. elseif(empty($_POST['message']))
  21. {
  22.  
  23.    echo 'Nie podałeś treści!';
  24.  
  25. }
  26. elseif(!$_POST['zgoda1']=='1')
  27. {
  28.  
  29. echo "Nie potwierdzono: Wyrażam zgodę na przetwarzanie moich danych w formularzu";
  30.  
  31. }
  32. elseif(!$_POST['zgoda2']=='1')
  33. {
  34.  
  35. echo "Nie potwierdzono: Potwierdzam, że dane wypełniłem prawidłowo";
  36.  
  37. }
  38. else
  39. {
  40.  
  41.  
  42.  
  43. class MicroMailer{
  44.  var $to         = "";
  45.  var $subject    = "";
  46.  var $message    = "";
  47.  var $fromName   = "";
  48.  var $fromEmail  = "";
  49.  var $header     = "";
  50.  var $type       = "text/plain";
  51.  var $characterSet = "utf-8";
  52.  
  53.  
  54.  function send(){
  55.      $this->createHeader();
  56.      if (@mail($this->to,$this->subject,$this->message,$this->header)){
  57.          return true;
  58.      } else {
  59.          return false;
  60.      }
  61.  }
  62.  
  63. function createHeader(){
  64.      $from   = "From: $this->fromName <$this->fromEmail>r\n";
  65.      $replay = "Reply-To: $this->fromEmailr\n";  
  66.      $params = "MIME-Version: 1.0r\n";
  67.      $params = "Content-type: $this->type; charset=$this->characterSetr\n";
  68.  
  69.      $this->header = $from.$replay.$params;
  70.      return $this->header;
  71.  }
  72.  
  73. }
  74.  
  75.  
  76.    $mailer = new MicroMailer();
  77.  
  78.    $mailer->to         = isset($_POST["to"]) ? $_POST["to"] : "";
  79.    $mailer->fromName   = isset($_POST["fromname"]) ? $_POST["fromname"] : "";
  80.    $mailer->fromEmail  = isset($_POST["fromemail"]) ? $_POST["fromemail"] : "";
  81.    $mailer->subject    = isset($_POST["subject"]) ? $_POST["subject"] : "";
  82.    $mailer->message    = isset($_POST["message"]) ? $_POST["message"] : "";
  83. if ($mailer->send()) {
  84.      echo "Wiadomość wysłana!";
  85.    } else {
  86.      echo "Błąd podczas wysyłania wiadomości!";
  87.    }
  88.  
  89. }
  90. }
  91. ?>



  1. <input type="submit" value="Wyślij!" />
  2. <!-- Na -->
  3. <input type="submit" name="submit" value="Wyślij!" />
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 6.10.2025 - 22:22