Quantcast
Channel: birghtyoursite » magento
Viewing all articles
Browse latest Browse all 3

a easy way add a contact page with captcha in magento

$
0
0

How easy it?

if you are not familiar with magento and know php , this is the best and easy way for you to add a contact page with captcha in magento.

What’s needed?

As a contact page , we only need when client submit their information send a email and then if success show a thanks page while not show errors , ask the client to try again . so we need a email script and captcha script . We will use a phpmailer to send email and recaptcha.net captcha .

How it work?

First,we need a email script with phpmailer and register at recaptcha.net to get a public and private key for your magento site .Let’s create a
contact us page and a contact thanks page in magento via magento cms , then put your email script form
in contact us page ,for instance :

<form enctype="multipart/form-data" action="http://yoursite.com/contact.php" method="post" id="form">
<div class="row">
<label>Name:</label>
<input type="text"  name="Name">
</div>
<div class="row">
<label>E-mail:</label>
<input type="text"  name="Email">
</div>
<div class="row">
<label>Fax:</label>
<input type="text"   name="Fax">
</div>
<div class="row">
<label>Message:</label>
<textarea rows="5" name="Message" cols="45"></textarea><br />
<div>
<br />
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Ld_5woAAAAAAK-s6mYybMpCNpL-zwnGeY10idhn" ></script>
<br />
<input type="reset" value="Clear"> &nbsp; <input type="submit" value="Send">
</div>
</div>
 <div class="clear"></div>
</form>

Please take a notice for following codes :

 <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Ld_5woAAAAAAK-s6mYybMpCNpL-zwnGeY10idhn" ></script>

You should replace ’6Ld_5woAAAAAAK-s6mYybMpCNpL-zwnGeY10idhn’ with your recaptcha.net public key , that’s use to create the captcha .

Then upload recaptchalib.php and your contact.php which used to process the contact form to your site root directory.the contact page should like :

include_once("phpmailer/class.phpmailer.php");
include_once("phpmailer/class.smtp.php");
include_once("recaptchalib.php");
$privatekey = "6Ld_5woAAAAAAGNVXku4-wDQtvYFUOxeeoPE4Avn";
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);
 
        if ($resp->is_valid) {
                                      /*... phpmailer send email script....*/
                                     if($mail->Send())
                                      {
                                          header("Location:http://www.caterline.co.uk/contact-thanks"); 
                                        }
                                      else
                                      {
	                                   echo "this is error when sending email ! <a href='http://www.caterline.co.uk/contactusorm'>try again</a>";
                                        }
                                       /*... phpmailer send email script....*/
                                }
}

You may notice the codes:

$privatekey = "6Ld_5woAAAAAAGNVXku4-wDQtvYFUOxeeoPE4Avn";

yes,you should replace ’6Ld_5woAAAAAAGNVXku4-wDQtvYFUOxeeoPE4Avn’ with your private key . Up to now , all finished . enjoy it !

Online demo

magento contact page with captcha and attachment (phpmailer send mail with attachment):
http://dev.caterequipment.com/contact-us

Download source codes

magento-captcha-contact-form.zip


Viewing all articles
Browse latest Browse all 3

Trending Articles