Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problem z formularzem kontaktowym
sasadam
post 26.02.2015, 09:37:55
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 15.04.2014

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


witam, mam mały problem z formularzem kontaktowym na mojej stronie, mianowicie plik o nazwie "contact-form.php" umieszczony w folderze "php" wygląda następująco:

  1. <?php
  2. header('Expires: ' . gmdate('r', 0));
  3.  
  4. header('Content-type: application/json');
  5.  
  6. require 'php-mailer/class.phpmailer.php';
  7.  
  8. // Your email address
  9. $to = 'kontakt@umiem-pomagam.pl';
  10.  
  11. $subject = $_POST['subject'];
  12.  
  13. if($to) {
  14.  
  15. $name = $_POST['name'];
  16. $email = $_POST['email'];
  17.  
  18. $fields = array(
  19. 0 => array(
  20. 'text' => 'Name',
  21. 'val' => $_POST['name']
  22. ),
  23. 1 => array(
  24. 'text' => 'Email address',
  25. 'val' => $_POST['email']
  26. ),
  27. 2 => array(
  28. 'text' => 'Message',
  29. 'val' => $_POST['message']
  30. )
  31. );
  32.  
  33. $message = "";
  34.  
  35. foreach($fields as $field) {
  36. $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  37. }
  38.  
  39. $mail = new PHPMailer;
  40.  
  41. $mail->IsSMTP(); // Set mailer to use SMTP
  42.  
  43. // Optional Settings
  44. //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
  45. //$mail->SMTPAuth = true; // Enable SMTP authentication
  46. //$mail->Username = 'username'; // SMTP username
  47. //$mail->Password = 'secret'; // SMTP password
  48. //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  49.  
  50. $mail->From = $email;
  51. $mail->FromName = $_POST['name'];
  52. $mail->AddAddress($to); // Add a recipient
  53. $mail->AddReplyTo($email, $name);
  54.  
  55. $mail->IsHTML(true); // Set email format to HTML
  56.  
  57. $mail->CharSet = 'UTF-8';
  58.  
  59. $mail->Subject = $subject;
  60. $mail->Body = $message;
  61.  
  62. if(!$mail->Send()) {
  63. $arrResult = array ('response'=>'error');
  64. }
  65.  
  66. $arrResult = array ('response'=>'success');
  67.  
  68. echo json_encode($arrResult);
  69.  
  70. } else {
  71.  
  72. $arrResult = array ('response'=>'error');
  73. echo json_encode($arrResult);
  74.  
  75. }
  76. ?>



natomiast kod na stronie html w dzile kontakt wygląda tak:

  1. <!--Contact form-->
  2. <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-pad wow fadeInLeft" data-wow-delay="0.5s" data-wow-offset="100">
  3.  
  4. <form class="contact2-page-form col-lg-8 col-sm-12 col-md-8 col-xs-12 no-pad contact-v2" id="contactForm">
  5.  
  6.  
  7. <div class="form-title-text no-pad">Skontaktuj się z nami za pośrednictwem formularza</div>
  8.  
  9.  
  10. <div class="alert alert-success hidden col-lg-12 col-sm-12 col-md-12 col-xs-12" id="contactSuccess">
  11. <strong>Sukces!</strong> Wiadomość została wysłana.
  12. </div>
  13.  
  14. <div class="alert alert-error hidden col-lg-12 col-sm-12 col-md-12 col-xs-12" id="contactError">
  15. <strong>Błąd!</strong> Wystąpił niespodziewany błąd. Prosimy skontaktoqwać się w sposób tradycyjny..
  16. </div>
  17.  
  18. <div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
  19. <input type="text" class="contact2-textbox" placeholder="Imie i nazwisko*" name="name" id="name" />
  20. </div>
  21.  
  22. <div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
  23. <input type="email" class="contact2-textbox" placeholder="Email*" name="email" id="email"/>
  24. </div>
  25.  
  26. <div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
  27. <input type="text" placeholder="Tytuł*" class="contact2-textbox" name="subject" id="subject">
  28. </div>
  29.  
  30.  
  31.  
  32. <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
  33. <textarea class="contact2-textarea" placeholder="Tresc zapytania..." name="message" id="message"></textarea>
  34. </div>
  35.  
  36. <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
  37. <section class="color-7" id="btn-click">
  38. <button class="icon-mail btn2-st2 btn-7 btn-7b" data-loading-text="Loading..." type="submit">Wyslij</button>
  39.  
  40. </section>
  41. </div>
  42.  
  43.  
  44. </form>



Mój problem polega na tym, że po wpisaniu treści w formularzu na stronie www... pojazwia się tylko komunikat, że wiadomość została wysłana, jednak nic nie dochodzi na skrzynkę... w kodzie html widzę, że nie ma żadnego odwołania do pliku php odpowiedzialnego za proawidłową wysyłke na wskazany adres... możecie mi powiedziec jak dokładnie i gdzie w kodzie html mam dopisać połaćzenie do skryptu php? bo chyba w tym jest problem.

z góry dziękuje za każdą pomoc, pozdrawiam serdecznie, Adam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
DraGo110
post 26.02.2015, 13:38:12
Post #2





Grupa: Zarejestrowani
Postów: 27
Pomógł: 6
Dołączył: 22.12.2009
Skąd: Katowice

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


Xxxxxx lat temu znalazłem fajną funkcje ( dużo mniejsza niż php mailer ) opiera ona się na połączeniu Fsock
są to tylko dwa pliki - skoro użyasz SMTP myślę ze dasz rade ją skonfigurowac pod siebie - jak cos pytaj smile.gif



w swoim formularzu przekazujesz dane do funkcji

  1. $to = "email@email.pl"; // odbiorca
  2. $from = $_POST['email']; // nadawca
  3. $subject = "temat"; // temat
  4. $body = $_POST['tresc']; //tresc
  5. $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
  6. $SMTPChat = $SMTPMail->SendMail();
  7.  



oraz SMTP.class.php

  1. <?php
  2. class SMTPClient
  3. {
  4.  
  5. function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
  6. {
  7.  
  8. $this->SmtpServer = $SmtpServer;
  9. $this->SmtpUser = base64_encode ($SmtpUser);
  10. $this->SmtpPass = base64_encode ($SmtpPass);
  11. $this->from = $from;
  12. $this->to = $to;
  13. $this->subject = $subject;
  14. $this->body = $body;
  15.  
  16. if ($SmtpPort == "")
  17. {
  18. $this->PortSMTP = 25;
  19. }
  20. else
  21. {
  22. $this->PortSMTP = $SmtpPort;
  23. }
  24. }
  25.  
  26. function SendMail ()
  27. {
  28. if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
  29. {
  30. fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
  31. $talk["hello"] = fgets ( $SMTPIN, 1024 );
  32. fputs($SMTPIN, "auth login\r\n");
  33. $talk["res"]=fgets($SMTPIN,1024);
  34. fputs($SMTPIN, $this->SmtpUser."\r\n");
  35. $talk["user"]=fgets($SMTPIN,1024);
  36. fputs($SMTPIN, $this->SmtpPass."\r\n");
  37. $talk["pass"]=fgets($SMTPIN,256);
  38. fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
  39. $talk["From"] = fgets ( $SMTPIN, 1024 );
  40. fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
  41. $talk["To"] = fgets ($SMTPIN, 1024);
  42. fputs($SMTPIN, "DATA\r\n");
  43. $talk["data"]=fgets( $SMTPIN,1024 );
  44. fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
  45. $talk["send"]=fgets($SMTPIN,256);
  46. //CLOSE CONNECTION AND EXIT ...
  47. fputs ($SMTPIN, "QUIT\r\n");
  48. fclose($SMTPIN);
  49. //
  50. }
  51. return $talk;
  52. }
  53. }
  54. ?>


No i przydał by ci sie jeszcze plik z konfigruacją konta np. SMTP.config.php

  1. <?php
  2. //Server Address
  3. $SmtpServer="SERWER";
  4. $SmtpPort="port"; //default ( 25 )
  5. $SmtpUser="USER";
  6. $SmtpPass="PASS";
  7. ?>
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 Wersja Lo-Fi Aktualny czas: 27.06.2025 - 11:20