943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 86
  • PHP RSS
Aug 30th, 2010
0

Would anyone be able to show me how to add a recaptcha to my php mail form

Expand Post »
i can't figure out how to get recaptcha to work with my code properly and i'm just learning to code i was wondering if anyone could help with my coding. heres my code below and thanks in advance.


php Syntax (Toggle Plain Text)
  1. <html><head> <meta name="GENERATOR" content="Evrsoft First Page"> <style>#conash3D0 { DISPLAY: none } </style> </head> <body>Harry Potter Book 5
  2.  
  3. <?php // Change below to the email address where you want to receive the message. // (inside the quote marks 'receive@yourdomain.com'') $myemail = 'billyf431@gmail.com'; $autorespond = '$email'; $from = 'billyf431@gmail.com'; $test = 'billy431@live.ca'; $to = '$email';$subject = 'Harry Potter 7 Book Order'; $subject2 = 'Order recieved'; $op = $_POST[op];if($op == 'contact') { $name = stripslashes($_POST[name]); $email = stripslashes($_POST[email]); $phone = stripslashes($_POST[phone]); $goderich = stripslashes($_POST[goderich]); $kincardine = stripslashes($_POST[kincardine]);if(!$name) { $status = "Please enter your name.
  4. "; } if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$",$email)) { $status .= "We're sorry, but you've entered an incorrect email address.
  5. "; } if(!eregi("^[0-9]{3}-[0-9]{3}-[0-9]{4}$",$phone)) { $status .= "You have entered and invalid phone number or not included '-' dashes.
  6. "; } if(!$status) { $header = "From: $emailrnReply-To: $emailrn"; $header2 = "From: $myemailrnReply-To: $emailrn";$message = " Name: $name Email: $email Phone Number: $phone Goderich: $goderich Kincardine: $kincardine "; $message2 = " We Have Recieved Your Order and Will $to Have it ready for pickup within 48 hours if the item is not avalible you will recieve an ";if(mail($myemail, $subject, $message, $header)) if(mail($email, $subject2, $message2, $header2)) { $status = "Thank you for your Order
  7.  
  8. "; } else { $status = "There was a problem sending your order, please try again later.
  9.  
  10. "; }} else { $status .= "
  11. Please press Resubmit Form to resubmit.
  12.  
  13. "; } }$referer = $_SERVER[HTTP_REFERER];if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer)) { unset($referer); }?><?php print $status; ?> <form method="post" action="&lt;?php print $_SELF; ?&gt;" &gt;<input="" value="contact" type="hidden" name="op"> Name:
  14. <input size="35" name="name">
  15. E-mail address:
  16. <input size="35" name="email">
  17.  
  18. Phone Number:
  19. <input size="35" name="phone">
  20. Store:
  21. <input value="X" type="checkbox" name="goderich">Goderich
  22. <input value="X" type="checkbox" name="kincardine">Kincardine
  23.  
  24.  
  25. @require_once('recaptchalib.php'); $publickey = "6LdiiLwSAAAAAKRgkcUtC7nZxQthhiUBA1W9-wEu"; $privatekey = "6LdiiLwSAAAAADdLBwN4gCEgv47JDRNghGwY4pgB";
  26.  
  27. $resp = null; $error = null;
  28.  
  29. if ($_POST["submit"]) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
  30.  
  31. if ($resp->is_valid) {
  32.  
  33. echo "
  34. Email sent!
  35.  
  36. "; exit(1);
  37.  
  38. } else { echo "Sorry cannot send email as you've failed to provide correct captcha! Try again..."; } } echo recaptcha_get_html($publickey, $error); ?>
  39.  
  40.  
  41. <input value=" Submit Order" type="submit"> </form>
  42.  
  43. </body></html>
  44.  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
billy431 is offline Offline
1 posts
since Aug 2010
Sep 10th, 2010
0

Code Correction

Hello billy431,
Looks like it has been more than a week since you posted your query. I hope you have got your problem fixed by now. However, i looked at your codes and corrected the errors i found. Hers is the code:
php Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <meta name="GENERATOR" content="Evrsoft First Page">
  4. <style>#conash3D0 { DISPLAY: none } </style>
  5. </head>
  6. <body>Harry Potter Book 5
  7.  
  8. <?php // Change below to the email address where you want to receive the message. // (inside the quote marks 'receive@yourdomain.com'')
  9. $myemail = 'billyf431@gmail.com';
  10. $autorespond = '$email';
  11. $from = 'billyf431@gmail.com';
  12. $test = 'billy431@live.ca';
  13. $to = '$email';
  14. $subject = 'Harry Potter 7 Book Order';
  15. $subject2 = 'Order recieved';
  16. $op = $_POST['op'];
  17. if ($op == 'contact') {
  18. $name = stripslashes($_POST['name']);
  19. $email = stripslashes($_POST['email']);
  20. $phone = stripslashes($_POST['phone']);
  21. $goderich = stripslashes($_POST['goderich']);
  22. $kincardine = stripslashes($_POST['kincardine']);
  23. if (!$name) {
  24. $status = "Please enter your name.
  25. ";
  26. }
  27. if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
  28. $status .= "We're sorry, but you've entered an incorrect email address.
  29. ";
  30. }
  31. if (!eregi("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone)) {
  32. $status .= "You have entered and invalid phone number or not included '-' dashes.
  33. ";
  34. }
  35. if (!$status) {
  36. $header = "From: $emailrnReply-To: $emailrn";
  37. $header2 = "From: $myemailrnReply-To: $emailrn";
  38. $message = " Name: $name Email: $email Phone Number: $phone Goderich: $goderich Kincardine: $kincardine ";
  39. $message2 = " We Have Recieved Your Order and Will $to Have it ready for pickup within 48 hours if the item is not avalible you will recieve an ";
  40. if (mail($myemail, $subject, $message, $header))
  41. if (mail($email, $subject2, $message2, $header2)) {
  42. $status = "Thank you for your Order
  43.  
  44. ";
  45. } else {
  46. $status = "There was a problem sending your order, please try again later.
  47.  
  48. ";
  49. }
  50. } else {
  51. $status .= "
  52. Please press Resubmit Form to resubmit.
  53.  
  54. ";
  55. }
  56. }
  57. $referer = $_SERVER['HTTP_REFERER'];
  58. if (!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer)) {
  59. unset($referer);
  60. } ?>
  61.  
  62. <?php print $status; ?>
  63. <form method="post" action="&lt;?php print $_SELF; ?&gt;" &gt;<input="" value="contact" type="hidden" name="op"> Name:
  64. <input size="35" name="name">
  65. E-mail address:
  66. <input size="35" name="email">
  67.  
  68. Phone Number:
  69. <input size="35" name="phone">
  70. Store:
  71. <input value="X" type="checkbox" name="goderich">Goderich
  72. <input value="X" type="checkbox" name="kincardine">Kincardine
  73.  
  74. <?php
  75. @require_once('recaptchalib.php'); $publickey = "6LdiiLwSAAAAAKRgkcUtC7nZxQthhiUBA1W9-wEu"; $privatekey = "6LdiiLwSAAAAADdLBwN4gCEgv47JDRNghGwY4pgB";
  76.  
  77. $resp = null; $error = null;
  78.  
  79. if ($_POST["submit"]) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
  80.  
  81. if ($resp->is_valid) {
  82.  
  83. echo "
  84. Email sent!
  85.  
  86. "; exit(1);
  87.  
  88. } else { echo "Sorry cannot send email as you've failed to provide correct captcha! Try again..."; } } echo recaptcha_get_html($publickey, $error); ?>
  89.  
  90.  
  91. <input value=" Submit Order" type="submit"> </form>
  92.  
  93. </body></html>

Please let me know if it still contains errors.
Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kcrazy is offline Offline
5 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: I really need to make this vertical
Next Thread in PHP Forum Timeline: Variable Mysteriously Stops Echoing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC