Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Capcha jak .?
run3
post 19.03.2016, 14:06:18
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 21.01.2011

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


Witam.
Mam taką zagadkę.Mam formularz wszystko ok działa. Ale chciałbym zabezpieczyć go poprzez capcha. Niestety nie mam pojęcia gdzie i do jakiego pliku wstawić kod.Aby dopiero po potwierdzeniu Capcha wysyłał.

Imam drugie pytanie. Jak w html5 ukryć przed robotami spamującymi adres email.

Kod formularza HTML

  1.  
  2. </section>
  3. <section class="well1">
  4. <div class="container">
  5. <h2>Wyślij wiadomość</h2>
  6. <form method="post" action="bat/sendmail.php" class="mailform off2">
  7. <input type="hidden" name="form-type" value="contact">
  8. <fieldset class="row">
  9. <label class="grid_4">
  10. <input type="text" name="name" placeholder="Twoje imię i nazwisko:" data-constraints="@LettersOnly @NotEmpty">
  11. </label>
  12. <label class="grid_4">
  13. <input type="text" name="phone" placeholder="Telefon:" data-constraints="@Phone">
  14. </label>
  15. <label class="grid_4">
  16. <input type="text" name="email" placeholder="Email:" data-constraints="@Email @NotEmpty">
  17. </label>
  18. <label class="grid_12">
  19. <textarea name="message" placeholder="Wiadomość:" data-constraints="@NotEmpty"></textarea>
  20. </label>
  21.  
  22. <div class="mfControls grid_12">
  23. <button type="submit" class="btn">Wyślij wiadomość</button>
  24. </div>
  25. </form>
  26. </div>
  27. </section>


Kod php formularza i pytanie jak poprawić linijkę by akceptował polskie znaki.

  1. <?php
  2.  
  3. $recipients = 'adres@adres.pl';
  4. //$recipients = '#';
  5.  
  6. try {
  7. require './phpmailer/PHPMailerAutoload.php';
  8.  
  9. preg_match_all("/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/", $recipients, $addresses, PREG_OFFSET_CAPTURE);
  10.  
  11. if (!count($addresses[0])) {
  12. die('MF001');
  13. }
  14.  
  15. if (preg_match('/^(127\.|192\.168\.)/', $_SERVER['REMOTE_ADDR'])) {
  16. die('MF002');
  17. }
  18.  
  19. $template = file_get_contents('rd-mailform.tpl');
  20.  
  21. if (isset($_POST['form-type'])) {
  22. switch ($_POST['form-type']){
  23. case 'contact':
  24. $subject = 'A message from your site visitor';
  25. break;
  26. case 'subscribe':
  27. $subject = 'Subscribe request';
  28. break;
  29. case 'order':
  30. $subject = 'Order request';
  31. break;
  32. default:
  33. $subject = 'A message from your site visitor';
  34. break;
  35. }
  36. }else{
  37. die('MF004');
  38. }
  39.  
  40. if (isset($_POST['email'])) {
  41. $template = str_replace(
  42. ["<!-- #{FromState} -->", "<!-- #{FromEmail} -->"],
  43. ["Email:", $_POST['email']],
  44. $template);
  45. }else{
  46. die('MF003');
  47. }
  48.  
  49. if (isset($_POST['message'])) {
  50. $template = str_replace(
  51. ["<!-- #{MessageState} -->", "<!-- #{MessageDescription} -->"],
  52. ["Message:", $_POST['message']],
  53. $template);
  54. }
  55.  
  56. preg_match("/(<!-- #{BeginInfo} -->)(.|\n)+(<!-- #{EndInfo} -->)/", $template, $tmp, PREG_OFFSET_CAPTURE);
  57. foreach ($_POST as $key => $value) {
  58. if ($key != "email" && $key != "message" && $key != "form-type" && !empty($value)){
  59. $info = str_replace(
  60. ["<!-- #{BeginInfo} -->", "<!-- #{InfoState} -->", "<!-- #{InfoDescription} -->"],
  61. ["", ucfirst($key) . ':', $value],
  62. $tmp[0][0]);
  63.  
  64. $template = str_replace("<!-- #{EndInfo} -->", $info, $template);
  65. }
  66. }
  67.  
  68. $template = str_replace(
  69. ["<!-- #{Subject} -->", "<!-- #{SiteName} -->"],
  70. [$subject, $_SERVER['SERVER_NAME']],
  71. $template);
  72.  
  73. $mail = new PHPMailer();
  74. $mail->From = $_SERVER['SERVER_ADDR'];
  75. $mail->FromName = $_SERVER['SERVER_NAME'];
  76.  
  77. foreach ($addresses[0] as $key => $value) {
  78. $mail->addAddress($value[0]);
  79. }
  80.  
  81. $mail->CharSet = 'utf-8';
  82. $mail->Subject = $subject;
  83. $mail->MsgHTML($template);
  84.  
  85. if (isset($_FILES['attachment'])) {
  86. foreach ($_FILES['attachment']['error'] as $key => $error) {
  87. if ($error == UPLOAD_ERR_OK) {
  88. $mail->AddAttachment($_FILES['attachment']['tmp_name'][$key], $_FILES['Attachment']['name'][$key]);
  89. }
  90. }
  91. }
  92.  
  93. $mail->send();
  94.  
  95. die('MF000');
  96. } catch (phpmailerException $e) {
  97. die('MF254');
  98. } catch (Exception $e) {
  99. die('MF255');
  100. }
  101.  
  102. ?>

Go to the top of the page
+Quote Post
viking
post 19.03.2016, 14:18:23
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Masz w dokumentacji opisane włącznie z kodem PHP: https://developers.google.com/recaptcha/intro#audience
Sprawdzasz w POST g-recaptcha-response


--------------------
Go to the top of the page
+Quote Post

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: 28.03.2024 - 19:00