how to get my contact form to do what i want it to!

Right well lets add the email validation to it as well, missed that so change this ~
if(!empty($_POST["email"])){
$email = $_POST["email"];
}else{


to~
if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err=$err."Your email address appears to be wrong,<br />";
}
}else{


Right now captcha's I don't tend to use them as they can be beaten, in fact I am unaware of 1 that can't. But lets try this~
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{


So the whole thing should now look like this ~

<?php
if(isset($_POST['name']))
{
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{
$count=0;
$err="Please fix the errors below to be able to contact me: <br />";
if(!empty($_POST["name"])){
$from = $_POST["name"];
}else{
$count++;
$err.="Please enter your name<br />";
} if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err.="Your email address appears to be wrong,<br />";
}
}else{
$count++;
$err.="You need to enter an email address so I can contact you<br />";
} if(!empty($_POST['mess'])){
$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
$content = $content . $_POST["mess"];
$content = wordwrap($content, 70);
}else{
$count++;
$err.="Your message was blank";
}
if($count==0){
mail('[email protected]', 'website inquiry', $content)?>
<h2>Success</h2>
<p>
Your message has been sent, and I will reply within 48hrs. Thank you.";
</p>
<?php }else{?>
<h2><?php if($count>1){echo $count;?> errors <?php }else{?>1 error <?php }?>occured</h2>
<p>
<?php echo $err;?>
</p>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n"<?php if(!empty($_POST["name"])){?> value="<?php echo $_POST['name'];?>"<?php }?> />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e"<?php if(!empty($_POST["email"])){?> value="<?php echo $_POST['email'];?>"<?php }?> />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }
}
}else{
?>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n" />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e" />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }?>


Yeah your totally right MCB, I've amended the above script, I had an issue with my CMS yesterday and i just thought ahhhhh so changed it like that but you are totally right.

Right check that now it should be fine, any errors let me know.

Jaz
 
What are you getting when you complete the form?
<h2>1 error occured</h2>

Or
Your message has been sent, and I will reply within 48hrs. Thank you.
 
got this,


Parse error: syntax error, unexpected ';' in /Applications/XAMPP/xamppfiles/htdocs/rootfolder web/home/contact/contact.php on line 151

lines 150 - 153 are,

PHP:
}else{
$count=++;
$err=$err."Please enter your name<br />";
 
before i was getting the "Your message has been sent, and I will reply within 48hrs. Thank you."
now i get the above when trying to o on the conact page

Z
 
Take out the equals sign so ~
}else{
$count++;
$err=$err."Please enter your name<br />";


My fault missed it in editing.
 
sorted!!! all good in the hood!

thankyou so much for this! truly appreciated!!

i guess now i just go to see if it sends? i get the thankyou your message has been sent.. page, dont get no emails tho? is it just a case of getting the website hosted and testing it?

Z
 
Hay I've just run it locally and it's working fine for me, I can't test with the captcha but I know the rest is fine bar 1 change.
Re-copy my script and try it again.
When the email is sent you will get this error ~

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or
That just means that my local server is not set up to send emails, once it was loaded on to my server that error wouldn't occur and the email would be sent.

In fact I like it that much I'm going to change 1 of my clients contact pages to include the number of errors in the header if an error occurs.
 
Notice I did correct 1 more error that was changing this line ~
<p>
<textarea name="mess" cols="50" rows="20" id="m"><?php if(!empty($_POST["message"])){?><?php echo $_POST['message'];}?></textarea>
</p>

To~
<p>
<textarea name="mess" cols="50" rows="20" id="m"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>


If you get the error i put above it should send fine.
O it's fine it's technically my break from CMS coding so makes a change from interacting with a DB for a while, not much of a break though, awww.....anyhoo..... :(
 
i thank thee, i am most grateful!

well hopefully my site is now ready to go, a few tweaks here and there! once its done i will add a link for some feedback. maybe you could send a message through the contact form saying what you think!!!

the next step is getting it online! look out for another thread from bentzak!!!

Cheers again,

Zak
 
Back
Top