Tapi tiada waktu terlambat buat belajar dan mencoba. Tutorial aslinya berasal dari http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html
Pertama sediakan sebuah form HTML, ini hanya Sintaks HTML biasa
<HTML>
<HEAD><title>Contact Form</title></HEAD>
<BODY>
<form method="POST" name="contact_form" action="result.php">
Enter Name: <input type="text" name="name"><br>
Enter Message: <textarea name="message"></textarea><br>
<img src="captcha_code_file.php" /><br>
Enter captcha Code Here :
<input id="6_letters_code" name="6_letters_code" type="text" ><br>
<input type="submit" value="Submit"><br>
</form>
</BODY>
</HTML>
File yang diperlukan lalu letakkkan file di folder yang sama (File HTML,
captcha_code_file.php
, Font Pendukung dan result.php). File dapat didownloadhttp://www.html-form-guide.com/contact-form/html-contact-form-captcha.zip
Oh ya, rename aja html_contac_form_proc.php dengan result.php
Test setelah itu dengan melihat di Localhost hasilnya..
adapun pengolahan terdapat di file result.php
<?php
session_start();
if( $_SESSION['6_letters_code'] == $_POST['6_letters_code'] && !empty($_SESSION['6_letters_code'] ) ) {
$to = "RecipientEmail@domain.com";
$email_subject = "This is the email subject";
$name = $_POST['name'];
$message = $_POST['message'];
$email_body = "You have received a new messag from " . $name . ". Here is the message: " . $message;
mail($to, $email_subject, $email_body);
echo 'You entered the correct code. Your message is successfully emailed.';
} else {
echo "Sorry, you have provided an invalid security code.
Please <a href='contact_form_with_captcha.html'>CLICK HERE</a> to try again.";
}
?>
Session harus disertakan untuk mem-post karakter,
Sintaks email dapat diabaikan
jika benar, maka proses dapat dilanjutkan sebaliknya jika salah akan muncul pesan kesalahan "Sorry, you have provided an invalid security code"
Tidak ada komentar:
Posting Komentar