Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Formularz kontaktowy, Pusty wynik z pola select
wbeatn
post
Post #1





Grupa: Zarejestrowani
Postów: 36
Pomógł: 1
Dołączył: 7.05.2007

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


Witam.
Mam skrypt służący do wysyłania wiadomości email z poziomu strony internetowej. Chcę aby adresat był wybierany z pola 'select' w formularzu.
W owym polu posiadam dwie opcje z różniącymi się od siebie emailami jako wartość 'value'. Niestety kiedy w kodzie PHP jako email podam "$_POST['getemail']" mail nie dociera do adresata. Kiedy zaś zamiast wartości $_POST wpiszę po prostu adres emailowy, wiadomość dochodzi bez problemu.

HTML

  1. <form action="contact.php" method="post" id="contactform">
  2. <ol>
  3. <li>
  4. <label>Adresat</label>
  5. <select name="getemail" class="text"><option value="email1@mail.com" selected="selected">Dyr. stategiczny</option><option value="email2@mail.com">Dyr. handlowy</option></select></td>
  6. </li>
  7. <li>
  8. <label for="name">Przedstaw się</label>
  9. <input id="name" name="name" class="text" />
  10. </li>
  11. <li>
  12. <label for="email">Twój email</label>
  13. <input id="email" name="email" class="text" />
  14. </li>
  15. <li>
  16. <label for="subject">Temat</label>
  17. <input id="subject" name="subject" class="text" />
  18. </li>
  19. <li>
  20. <label for="message">Wiadomość</label>
  21. <textarea id="message" name="message" rows="6" cols="50"></textarea>
  22. </li>
  23. <li class="buttons">
  24. <input type="image" name="imageField" id="imageField" src="imgs/send.gif" class="send" />
  25. <div class="clr"></div>
  26. </li>
  27. </ol>
  28. </form>


PHP

  1. <?php
  2. include('inc/system.php');
  3.  
  4. if(!$_POST) exit;
  5. $email = $_POST['email'];
  6.  
  7. //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
  8. if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
  9. $error.="Wpisano błędny adres email";
  10. $errors=1;
  11. }
  12. if($errors==1) echo $error;
  13. else{
  14.  
  15. $values = array ('name','email','message');
  16. $required = array('name','email','message');
  17.  
  18. $your_email = $_POST['getemail'];
  19. $email_subject = "New Message: ".$_POST['subject'];
  20. $email_content = '<div style="width: 60%; padding: 8px; margin-bottom: 2px; background: #252525; border: solid 1px #e4e4e4; font-size: 13px; color: #e8e8e8;"><b>Ta wiadomość została wysłana z formularza na stronie <a style="color: #a0a0a0; text-decoration: none;" href="http://www.xxx.com">www.xxx.com</a></b></div>';
  21. $header="From:$email\n";
  22. $header.="Content-Type: text/html; charset=utf-8\n";
  23.  
  24. foreach($values as $key => $value){
  25. if(in_array($value,$required)){
  26. if ($key != 'subject' && $key != 'company') {
  27. if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
  28. }
  29. $email_content .= '<div style="width: 60%; padding: 8px; margin-bottom: 2px; background: #f6f6f6; border: solid 1px #e4e4e4; font-size: 13px; color: #505050;">'.getforminput($_POST[$value]).'</div>';
  30. }
  31. }
  32.  
  33. if(@mail($your_email,$email_subject,$email_content,$header)) {
  34. echo 'Message sent!';
  35. } else {
  36. echo 'ERROR!';
  37. }
  38. }
  39. ?>


Wydaje się, że wszystko powinno działać. Niestety w przypadku użycia $_POST mail nie dociera na skrzynkę pocztową. Jak rozumiem z pola select nie pobiera wybranej opcji i wysyłany mail nie posiada adresata. Dlaczego ?

Ten post edytował wbeatn 31.03.2012, 00:03:06
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 03:53