Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Nie mogę wysłać formularza.
Forum PHP.pl > Forum > Przedszkole
Amakesh
Witam! Stworzyłam formularz kontaktowy, którego zawartość pól ma zostać wysłana na konkretny adres email. Niestety nie potrafię go uruchomić - przeglądarka ciągle wyrzuca mi taki błąd: E-mail nie mógł zostać wysłany, przyczyna :You must provide at least one recipient email address. error_reporting(E_ALL); ini_set('display_errors','1'); Kod formularza poniżej a ustawienia phpmailera w class phpmailer.php, którego zawartośc wkleiłam tutaj tutaj - nie miałam wyjścia, forum wyrzucalo komunikat, że post za długi. Bardzo proszę o pomoc

Formularz
  1. <?php
  2. require_once('class.phpmailer.php'); //dodanie klasy phpmailer
  3. require_once('class.smtp.php');
  4. $con = mysql_connect("localhost","root","toor","full");
  5. mysql_query("SET CHARSET utf8");
  6. mysql_query("SET NAMES `utf8` COLLATE `utf8_polish_ci`");
  7. mysql_select_db("full",$con);
  8. //display contact
  9. $q6 = "SELECT contactinfo FROM admin WHERE id=1";
  10. $q61 = mysql_query($q6);
  11.  
  12. $mail = new PHPMailer();
  13.  
  14.  
  15. if(isset($_POST['send'])){
  16.  
  17. //$email_to= ('solaris_ustronie@o2');
  18. $mail->AddAddress= ('solaris_ustronie@o2');
  19. $email_subject = "Zapytanie rezerwacyjne z formularza kontaktowego";
  20.  
  21.  
  22.  
  23. function died($error) {
  24. // your error code can go here
  25. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  26. echo "These errors appear below.<br /><br />";
  27. echo $error."<br /><br />";
  28. echo "Please go back and fix these errors.<br /><br />";
  29. die();
  30. }
  31.  
  32. // validation expected data exists
  33. /* if(!isset($_POST['name']) ||
  34.   !isset($_POST['telefon'])||
  35.   !isset($_POST['email'])) ||
  36. !isset($_POST['tytul'])) ||
  37. !isset($_POST['tresc'])){
  38.   died('We are sorry, but there appears to be a problem with the form you submitted.');
  39.   }*/
  40.  
  41. $uname = $_POST['name']; // required
  42. $tel = $_POST['telefon']; // required
  43. $email_from = $_POST['email']; // required
  44. $tytul = $_POST['tytul'];
  45. $tresc = $_POST['tresc']; // required
  46.  
  47. /* $error_message = "";
  48.   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  49.   if(!preg_match($email_exp,$email_from)) {
  50.   $error_message .= 'Niepoprawny adres Email .<br />';
  51.   }*/
  52. /*$string_exp = "/^[A-Za-z .'-]+$/";
  53.   if(!preg_match($string_exp,$username)) {
  54.   $error_message .= 'The Username you entered does not appear to be valid.<br />';
  55.   }*/
  56.  
  57. if (empty($_POST["email_from"])) {
  58. $emailErr = "Email wymagany";
  59. } else {
  60. // $email = test_input($_POST["email_from"]);
  61. // check if e-mail address is well-formed
  62. if (!filter_var($email_from, FILTER_VALIDATE_EMAIL)) {
  63. $emailErr = "Niepoprawny adres email";
  64. }
  65. }
  66. if (empty($_POST["tel"])) {
  67. $telErr = "Telefon wymagany";
  68. }
  69. if (!ctype_digit($_POST["tel"])) {
  70. $telErr = "Dozwolone tylko cyfry";
  71. }
  72. if((strlen($_POST["tel"]))<9){
  73. $telErr = "Musi zawierać min 9 cyfr";
  74. }
  75. if (empty($_POST["name"])) {
  76. $nameErr = "Imię i nazwisko wymagane";
  77. } else {
  78. // $name = test_input($_POST["name"]);
  79. // check if name only contains letters and whitespace
  80. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  81. $nameErr = "Dozwolone tylko litery";
  82. }
  83. }
  84. if (empty($_POST["tresc"])) {
  85. $comment = "Treść wiaoomości wymagana";
  86. } /*else {
  87.   $comment = test_input($_POST["tresc"]);
  88.   }*/
  89. if(strlen($error_message) > 0) {
  90. died($error_message);
  91. }
  92. $email_message = "Form details below.\n\n";
  93.  
  94. function clean_string($string) {
  95. $bad = array("content-type","bcc:","to:","cc:","href");
  96. return str_replace($bad,"",$string);
  97. }
  98.  
  99. $email_message .= "Imię i nazwisko: ".clean_string($name)."\n";
  100. $email_message .= "Telefon: ".clean_string($tel)."\n";
  101. $email_message .= "Email: ".clean_string($email_from)."\n";
  102. $email_message .= "Tytuł wiadomości: ".clean_string($tytul)."\n";
  103. $email_message .= "Treść wiadomości: ".clean_string($tresc)."\n";
  104.  
  105. $email_message .= "AddReplyTo: ".clean_string('$email_from','$name')."\n";
  106.  
  107.  
  108. // create email headers
  109. $headers = 'From: '.$email_from."\r\n".
  110. 'Reply-To: '.$email_from."\r\n" .
  111. 'X-Mailer: PHP/' . phpversion();
  112. @mail($email_to, $email_subject, $tytul, $email_message, $headers);
  113. }
  114.  
  115. if($mail->Send())
  116. {
  117. echo $confirm = "<b style='color:green'>Wiadomość została wysłana</b>";
  118. }
  119. else
  120. {
  121. echo 'E-mail nie mógł zostać wysłany, przyczyna :'. $mail->ErrorInfo;
  122. }
  123. $mail->ClearAddresses();
  124. $mail->ClearAttachments();
  125. //Redirect to Thank You HTML page after email is sent
  126.  
  127.  
  128. ?>

  1. error_reporting(E_ALL);
  2. ini_set('display_errors','1');
  3.  
  4. <div align="top">
  5. <form method="post">
  6. <table width="988" height="693" border="0" colspan="2">
  7. <tr>
  8. <td width="988" height="34" style=" position: absolute; top: 598px; left: 285px;" border="1"><center>
  9. <h1><center><strong style="color:191B7E; font: 23px Hobo Std;">Dane Kontaktowe</strong></center></h1>
  10. <div align="center">
  11. <p><b><?php while($contactdisp = mysql_fetch_array($q61)){echo $contactdisp['contactinfo'];} ?></p>
  12. </div>
  13. </center></td>
  14. </tr>
  15. <tr>
  16. <th height="626" bgcolor="">
  17. <fieldset style="display:inline-flex; height: 550px; width: 560px; color:191B7E; position:absolute; top:740px; left:500px;"><legend ><font size="+2">Formularz Kontaktowy</font></legend>
  18. <div style ="position: absolute; top: 35px; left:125px; slign:center;"><p>Pola oznaczone symbolem * są wymagane<p></br>
  19. </br><p><font size="+1">&nbsp;&nbsp;&nbsp; *Imię i nazwisko : </font><input type="text" name="name" placeholder=" Podaj swoje imię i nazwisko" style="height:30px; width:250px; "></br>
  20. </br><p><font size="+1">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *Telefon : </font><input type="tel" name="telefon" placeholder="Podaj swój numer telefonu" style="height:30px; width:250px;"maxlength = "15"></br>
  21. </br><p><font size="+1">&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *Email : </font><input type="email" name="email" placeholder="Podaj swój adres email" style="height:30px; width:250px;"></p>
  22. </br><p><font size="+1">&nbsp;&nbsp;&nbsp;Tytuł wiadomości : </font><input type="text" name="tytul" placeholder="Podaj tytuł wiadomości" style="height:30px; width:250px;"></p>
  23. </br><p><font size="+1">*Treść wiadomości : </font><input type="text" name="tresc" placeholder="Podaj treść wiadomości" style="height:150px; width:250px;"></p></div>
  24. <div style="position: absolute; top: 480px; left:305px;"><p><input type="submit" value="Wyślij" name="send">&nbsp;<input type="reset" value="Wyczyść"></p></div></fieldset>
  25. </th>
  26. </tr>
  27.  
  28. </tbody>
  29. </form>
  30. </div>
  31.  


nospor
Komunikat bledu mowi wyraźnie: nie podalas adresata....

mail($email_to, $email_subject, $tytul, $email_message, $headers);
Przeciez zmienna $email_to nigdzie nie jest inicjalizowa wiec adresat nie istnieje
freemp3
W adresie e-mail zapomniałeś dodać .pl po o2 smile.gif
Amakesh
A czy to
  1. $mail->AddAddress= ('solaris_ustronie@o2');
nie powinno wystarczyć?
nospor
No dobra, to po co robisz mail() skoro korzystasz z PHPMailera?
Amakesh
Opierałam się na tym http://phpedia.pl/wiki/Phpmailer z tym że dane takie jak host, login, haslo etc mam w class phpmailer.php, żeby nie umieszczać hasła w kodzie strony.
nospor
Nigdzie tam nie masz napisane, ze masz jeszcze uzywac funkcji mail()... wywal ją. ALbo uzywasz PHPMailer albo nie. Zdecyduj sie.
Amakesh
Ok, uporałam się z błędami. Wygląda na to że działa, ale..maile nie dochodzą. Dlaczego?
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.