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
</section>
<section class="well1">
<h2>Wyślij wiadomość
</h2> <form method="post" action="bat/sendmail.php" class="mailform off2"> <input type="hidden" name="form-type" value="contact"> <input type="text" name="name" placeholder="Twoje imię i nazwisko:" data-constraints="@LettersOnly @NotEmpty"> <input type="text" name="phone" placeholder="Telefon:" data-constraints="@Phone"> <input type="text" name="email" placeholder="Email:" data-constraints="@Email @NotEmpty"> <textarea name="message" placeholder="Wiadomość:" data-constraints="@NotEmpty"></textarea>
<div class="mfControls grid_12"> </section>
Kod php formularza i pytanie jak poprawić linijkę by akceptował polskie znaki.
<?php
$recipients = 'adres@adres.pl';
//$recipients = '#';
try {
require './phpmailer/PHPMailerAutoload.php';
preg_match_all("/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/", $recipients, $addresses, PREG_OFFSET_CAPTURE
);
if (!count($addresses[0
])) { }
if (preg_match('/^(127\.|192\.168\.)/', $_SERVER['REMOTE_ADDR'])) { }
if (isset($_POST['form-type'])) { switch ($_POST['form-type']){
case 'contact':
$subject = 'A message from your site visitor';
break;
case 'subscribe':
$subject = 'Subscribe request';
break;
case 'order':
$subject = 'Order request';
break;
default:
$subject = 'A message from your site visitor';
break;
}
}else{
}
if (isset($_POST['email'])) { ["<!-- #{FromState} -->", "<!-- #{FromEmail} -->"],
["Email:", $_POST['email']],
$template);
}else{
}
if (isset($_POST['message'])) { ["<!-- #{MessageState} -->", "<!-- #{MessageDescription} -->"],
["Message:", $_POST['message']],
$template);
}
preg_match("/(<!-- #{BeginInfo} -->)(.|\n)+(<!-- #{EndInfo} -->)/", $template, $tmp, PREG_OFFSET_CAPTURE
); foreach ($_POST as $key => $value) {
if ($key != "email" && $key != "message" && $key != "form-type" && !empty($value)){ ["<!-- #{BeginInfo} -->", "<!-- #{InfoState} -->", "<!-- #{InfoDescription} -->"],
$tmp[0][0]);
$template = str_replace("<!-- #{EndInfo} -->", $info, $template); }
}
["<!-- #{Subject} -->", "<!-- #{SiteName} -->"],
[$subject, $_SERVER['SERVER_NAME']],
$template);
$mail = new PHPMailer();
$mail->From = $_SERVER['SERVER_ADDR'];
$mail->FromName = $_SERVER['SERVER_NAME'];
foreach ($addresses[0] as $key => $value) {
$mail->addAddress($value[0]);
}
$mail->CharSet = 'utf-8';
$mail->Subject = $subject;
$mail->MsgHTML($template);
if (isset($_FILES['attachment'])) { foreach ($_FILES['attachment']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['attachment']['tmp_name'][$key], $_FILES['Attachment']['name'][$key]);
}
}
}
$mail->send();
} catch (phpmailerException $e) {
} catch (Exception $e) {
}
?>