Go Back   Singapore Web Hosting Talk > LEARNING CENTER > End User

End User For the end user. For people who use web hosting accounts.

Reply
 
Thread Tools
Old 30-04-2010, 12:39   #1
stevie
SGWHT Newbie
 
Join Date: 05-11-2009
Location: Malaysia
Posts: 99
stevie is on a distinguished road
PHP Contact Form with Verification Image

Contact forms are a great way to enable visitors to your site to contact you. But to prevent it abuse by spammer, the form with the verification image will help. For this example, you need to create 3 files index.php (form interface) and mailer.php (send mail script) , verificationimage.php (to check whether is valid visitor)

(a) Create a form in index.php that retrieve the information Subject, Email Account, Verification and Message

<form action="mailer.php" method="post" name="form1" id="form1" onsubmit="MM_validateForm('from','','RisEmail','su bject','','R','verif_box','','R','message','','R') ;return document.MM_returnValue">
Your e-mail:<br />
<input name="from" type="text" id="from" value="<?php echo $_GET['from'];?>"/>
<br />
Subject:<br />
<input name="subject" type="text" id="subject" value="<?php echo $_GET['subject'];?>"/>
<br />
Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" />
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
<br />
<?php if(isset($_GET['wrong_code'])){?>
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div>
<br />
<?php ;}?>
Message:<br />
<input name="message" cols="60" rows="5" id="message" value="<?php echo $_GET['message'];?>" />
<br />
<input name="Submit" type="submit" value="Send Message"/>
</form>


(b) Then create a send_contact.php with the code as below.

<?php
// Contact subject
$subject =$_POST['subject'];
// Details
$message=$_POST['detail'];
// Mail of sender
$mail_from=$_POST['customer_mail'];
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='test@test.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
__________________
Hosting Services = Hosting features + Customer Services + Technical Support
Linux hosting, Windows hosting, Email hosting, Semi dedicated server, dedicated server, VPS
********.sg | ********.in | ********.com
stevie is offline   Reply With Quote

Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT +8. The time now is 23:38.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright (C) 2002-2015 Brought to you by Singapore Web Hosting Talk (SGWHT). All Rights Reserved.