Need help with PHP Contact form, please

Reply

Join Date: Mar 2009
Posts: 4
Reputation: carthous is an unknown quantity at this point 
Solved Threads: 0
carthous carthous is offline Offline
Newbie Poster

Need help with PHP Contact form, please

 
0
  #1
Mar 27th, 2009
Ok im a complete noob to PHP. I'm trying to make a contact form. I had it working perfectly before. But now it seems that I have messed sometime up and I dont know what.

I'm using this code:
NOTE: I put the email address to blank@blank.com solely to not display my email address, I am using the correct email address on my site.

  1.  
  2. <?php
  3.  
  4. $my_email = "BLANK@BLANK.com";
  5.  
  6.  
  7. $continue = "/";
  8.  
  9. $errors = array();
  10.  
  11. // Remove $_COOKIE elements from $_REQUEST.
  12.  
  13. if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
  14.  
  15. // Check all fields for an email header.
  16.  
  17. function recursive_array_check_header($element_value)
  18. {
  19.  
  20. global $set;
  21.  
  22. if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
  23. else
  24. {
  25.  
  26. foreach($element_value as $value){if($set){break;} if ($value != “Submit”) {recursive_array_check_blank($value);}}
  27.  
  28. }
  29.  
  30. }
  31.  
  32. recursive_array_check_header($_REQUEST);
  33.  
  34. if($set){$errors[] = "You cannot send an email header";}
  35.  
  36. unset($set);
  37.  
  38. // Validate email field.
  39.  
  40. if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
  41. {
  42.  
  43. if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}
  44.  
  45. $_REQUEST['email'] = trim($_REQUEST['email']);
  46.  
  47. if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
  48.  
  49. }
  50.  
  51. // Check referrer is from same site.
  52.  
  53. if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
  54.  
  55. // Check for a blank form.
  56.  
  57. function recursive_array_check_blank($element_value)
  58. {
  59.  
  60. global $set;
  61.  
  62. if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
  63. else
  64. {
  65.  
  66. foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
  67.  
  68. }
  69.  
  70. }
  71.  
  72. recursive_array_check_blank($_REQUEST);
  73.  
  74. if(!$set){$errors[] = "You cannot send a blank form";}
  75.  
  76. unset($set);
  77.  
  78. // Display any errors and exit if errors exist.
  79.  
  80. if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
  81.  
  82. if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
  83.  
  84. // Build message.
  85.  
  86. function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
  87.  
  88. $message = build_message($_REQUEST);
  89.  
  90. $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."";
  91.  
  92. $message = stripslashes($message);
  93.  
  94. $subject = "FormToEmail Comments";
  95.  
  96. $headers = "From: " . $_REQUEST['email'];
  97.  
  98. mail($my_email,$subject,$message,$headers);
  99.  
  100. ?>
  101.  
  102. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  103.  
  104. <html>
  105.  
  106. <head>
  107. <title>Dreamweaver Tutorial - Contact Form</title>
  108. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  109. </head>
  110.  
  111. <body bgcolor="#ffffff" text="#000000">
  112.  
  113. <div>
  114. <center>
  115. <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
  116. <br>Your message has been sent
  117. <p><a href="<?php print $continue; ?>">Click here to continue</a></p>
  118. <p><b>Dreamweaver Spot</b> by <a href="http://dreamweaverspot.com">dreamweaverspot.com</a></p>
  119. </center>
  120. </div>
  121.  
  122. </body>
  123. </html>

Problem:

I am not receicing a message saying "You cannot send an email header" and nothing is sent to my email.

anyone know what this might be?? please and thank you!!!!
Last edited by carthous; Mar 27th, 2009 at 6:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 61
Reputation: Andrieux is an unknown quantity at this point 
Solved Threads: 4
Andrieux Andrieux is offline Offline
Junior Poster in Training

Re: Need help with PHP Contact form, please

 
0
  #2
Mar 27th, 2009
For the love of God, use [code] tags. +, there's way too much code for a contact form. Not going to read it without code tags, though. Too much work.
Last edited by Andrieux; Mar 27th, 2009 at 6:29 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: carthous is an unknown quantity at this point 
Solved Threads: 0
carthous carthous is offline Offline
Newbie Poster

Re: Need help with PHP Contact form, please

 
0
  #3
Mar 27th, 2009
I d/led this file from the internet. If you want to teach me how to make a smaller version of this ill listen. But this is all I got. Placed the code into the [code] tags. please see if you can tell me whats going on.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 61
Reputation: Andrieux is an unknown quantity at this point 
Solved Threads: 4
Andrieux Andrieux is offline Offline
Junior Poster in Training

Re: Need help with PHP Contact form, please

 
0
  #4
Mar 27th, 2009
http://www.kirupa.com/web/php_contact_form.htm

What errors are you getting?
Last edited by Andrieux; Mar 27th, 2009 at 6:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: carthous is an unknown quantity at this point 
Solved Threads: 0
carthous carthous is offline Offline
Newbie Poster

Re: Need help with PHP Contact form, please

 
0
  #5
Mar 27th, 2009
Originally Posted by Andrieux View Post
http://www.kirupa.com/web/php_contact_form.htm

What errors are you getting?
Thanks, Ok what is happening is that when I try to submit the contact form I am sent to a blank page that says: " " and no email is sent.

I founf that if I comment out ( remove) that part of code that is looking for an email header the email will be sent off fine. However I'm not sure if this is the correct solution to this problem.

Heres the part of code that it seems I'm having trouble with:

  1.  
  2. // Check all fields for an email header.
  3.  
  4. function recursive_array_check_header($element_value)
  5. {
  6.  
  7. global $set;
  8.  
  9. if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
  10. else
  11. {
  12.  
  13. foreach($element_value as $value){if($set){break;} if ($value != “Submit”) {recursive_array_check_blank($value);}}
  14.  
  15. }
  16.  
  17. }
  18.  
  19.  
  20. recursive_array_check_header($_REQUEST);
  21.  
  22. if($set){$errors[] = "You cannot send an email header";}
  23.  
  24. unset($set);

So is this code important? or can I just remove it? Also why would I all of a sudden start having problems with this, it was working fine before.

thank you,
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: carthous is an unknown quantity at this point 
Solved Threads: 0
carthous carthous is offline Offline
Newbie Poster

Re: Need help with PHP Contact form, please

 
0
  #6
Mar 27th, 2009
Originally Posted by Andrieux View Post
http://www.kirupa.com/web/php_contact_form.htm

What errors are you getting?
thanks for this tutorial, I'm definitly going to read this ^_^
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 426 | Replies: 5
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC