niadev Posted February 26, 2008 Share Posted February 26, 2008 I created a form at http://www.epd-qs-solutions.com/comments2.html (it originally went to a thank you page when the form was submitted but I've taken that page down in a feeble attempt at getting the form to work). For some reason the form will not email to me. ??? Here's the .php code (comments.php): # <?php # # $my_email = "nialldevlin@hotmail.com" ; # $formurl = "http://www.epd-qs-solutions.com/comments.htm" ; # $thankyouurl = "http://www.epd-qs-solutions.com/thankyou.htm" ; # # $uself = 0; # # $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; # $name = $_POST['Name'] ; # $telephone = $_POST['Telephone'] ; # $email = $_POST['Email'] ; # $companyname = $_POST['Company'] ; # $comments = $_POST['Questions/comments'] ; # $http_referrer = getenv( "HTTP_REFERER" ); # # $subject = "New comment from $name"; # # $message = # # "This message was sent from:\n" . # "$http_referrer\n" . # "------------------------------------------------------------\n\n" . # "Name: $name\n" . # "Email: $email\n" . # "Telephone: $telephone\n" . # "Company Name: $companyname\n\n" . # "------------------------- COMMENTS -------------------------\n\n" . # $comments . # "\n\n------------------------------------------------------------\n" ; # # mail($my_email, $subject, $message, # "From: \"EPD Q. S. Solutions Comment\" <service@noreply.epd-qs-solutions.com>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" ); # header( "Location: $thankyouurl" ); # exit ; # # ?> Here's a bit of code that I found online, it works ok for me: # <?php # # # # /* # # # # Thank you for choosing FormToEmail by FormToEmail.com # # # # Version 2.3 December 5th 2007 # # # # COPYRIGHT FormToEmail.com 2003 - 2007 # # # # You are not permitted to sell this script, but you can use it, copy it or distribute it, providing that you do not delete this copyright notice, and you do not remove any reference or links to FormToEmail.com # # # # For support, please visit: http://formtoemail.com/support/ # # # # You can get the Pro version of this script here: http://formtoemail.com/formtoemail_pro_version.php # # --------------------------------------------------------------------------------------------------- # # # # FormToEmail-Pro (Pro version) Features: # # # # Check for required fields. # # Attach file uploads. # # identiPIC Photo CAPTCHA system. # # Check for a set cookie. # # HTML output option. # # CSV output to attachment or file. # # Autoresponder. # # Show sender's IP address. # # Block IP addresses. # # Block web addresses or rude words. # # Block gobbledegook characters (≈ Á etc). # # Ignore fields. # # Sort fields. # # Auto redirect to "Thank You" page. # # No branding. # # # # --------------------------------------------------------------------------------------------------- # # # # FormToEmail DESCRIPTION # # # # FormToEmail is a contact-form processing script written in PHP. It allows you to place a form on your website which your visitors can fill out and send to you. The contents of the form are sent to the email address (or addresses) which you specify below. The form allows your visitors to enter their name, email address and comments. The script will not allow a blank form to be sent. # # # # Your visitors (and nasty spambots!) cannot see your email address. The script cannot be hijacked by spammers. # # # # When the form is sent, your visitor will get a confirmation of this on the screen, and will be given a link to continue to your homepage, or other page if you specify it. # # # # Should you need the facility, you can add additional fields to your form, which this script will also process without making any additional changes to the script. You can also use it to process other forms. The script will handle the "POST" or "GET" methods. It will also handle multiple select inputs and multiple check box inputs. If using these, you must name the field as an array using square brackets, like so: <select name="fruit[]" multiple>. The same goes for check boxes if you are using more than one with the same name, like so: <input type="checkbox" name="fruit[]" value="apple">Apple<input type="checkbox" name="fruit[]" value="orange">Orange<input type="checkbox" name="fruit[]" value="banana">Banana # # # # ** PLEASE NOTE ** If you are using the script to process your own forms (or older FormToEmail forms) you must ensure that the email field is named correctly in your form, thus: <input type="text" name="email" etc>. Note the lower case "email". If you don't do this, you won't be able to see who the email is from and the script won't be able to check the validity of the email. If you are using the form code below, you don't need to check for this. # # # # This is a PHP script. In order for it to run, you must have PHP (version 4.1.0 or later) on your webhosting account, and have the PHP mail() function enabled and working. If you are not sure about this, please ask your webhost about it. # # # # SETUP INSTRUCTIONS # # # # Step 1: Put the form on your webpage # # Step 2: Enter your email address and (optional) continue link below # # Step 3: Upload the files to your webspace # # # # Step 1: # # # # To put the form on your webpage, copy the code below as it is, and paste it into your webpage: # # # # <form action="FormToEmail.php" method="post"> # # <table border="0" bgcolor="#ececec" cellspacing="5"> # # <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr> # # <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> # # <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> # # <tr><td> </td><td><input type="submit" value="Send"><font face="arial" size="1"> <a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr> # # </table> # # </form> # # # # Step 2: # # # # Enter your email address. # # # # Enter the email address below to send the contents of the form to. You can enter more than one email address separated by commas, like so: $my_email = "bob@example.com,sales@example.co.uk,jane@example.com"; # # # # */ # # # # $my_email = "nialldevlin@hotmail.com"; # # # # /* # # # # Enter the continue link to offer the user after the form is sent. If you do not change this, your visitor will be given a continue link to your homepage. # # # # If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm" # # # # */ # # # # $continue = "/"; # # # # /* # # # # Step 3: # # # # Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace. IMPORTANT - The file name is case sensitive! You must save it exactly as it is named above! Do not put this script in your cgi-bin directory (folder) it may not work from there. # # # # THAT'S IT, FINISHED! # # # # You do not need to make any changes below this line. # # # # */ # # # # $errors = array(); # # # # // Remove $_COOKIE elements from $_REQUEST. # # # # if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} # # # # // Check all fields for an email header. # # # # function recursive_array_check_header($element_value) # # { # # # # global $set; # # # # if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}} # # else # # { # # # # foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);} # # # # } # # # # } # # # # recursive_array_check_header($_REQUEST); # # # # if($set){$errors[] = "You cannot send an email header";} # # # # unset($set); # # # # // Validate email field. # # # # if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) # # { # # # # if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";} # # # # $_REQUEST['email'] = trim($_REQUEST['email']); # # # # 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;}}}}}} # # # # } # # # # // Check referrer is from same site. # # # # 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";} # # # # // Check for a blank form. # # # # function recursive_array_check_blank($element_value) # # { # # # # global $set; # # # # if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} # # else # # { # # # # foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} # # # # } # # # # } # # # # recursive_array_check_blank($_REQUEST); # # # # if(!$set){$errors[] = "You cannot send a blank form";} # # # # unset($set); # # # # // Display any errors and exit if errors exist. # # # # if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} # # # # if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} # # # # // Build message. # # # # 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,", ");} # # # # $message = build_message($_REQUEST); # # # # $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com"; # # # # $message = stripslashes($message); # # # # $subject = "FormToEmail Comments"; # # # # $headers = "From: " . $_REQUEST['email']; # # # # mail($my_email,$subject,$message,$headers); # # # # ?> # # # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> # # # # <html> # # # # <head> # # <title>Form To Email PHP script from FormToEmail.com</title> # # <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> # # </head> # # # # <body bgcolor="#ffffff" text="#000000"> # # # # <div> # # <center> # # <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b> # # <br>Your message has been sent # # <p><a href="<?php print $continue; ?>">Click here to continue</a></p> # # <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p> # # </center> # # </div> # # # # </body> # # </html> I'm really desperate to get this fixed as I used this form in several sites and need to sort it out for clients ASAP. I'll provide additional information if needed. Any help is greatly appreciated! Niall Quote Link to comment Share on other sites More sharing options...
amites Posted February 26, 2008 Share Posted February 26, 2008 first thing I'd do is take that header line and turn it into a variable before hitting the mail command, if that doesn't work try removing the header part (you don't need it) and see if that works, then go from there Quote Link to comment Share on other sites More sharing options...
niadev Posted February 26, 2008 Author Share Posted February 26, 2008 Sorry, but do you mean: # $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; Quote Link to comment Share on other sites More sharing options...
niadev Posted February 26, 2008 Author Share Posted February 26, 2008 Apologies for bumping this post but this problem has been getting at me for days and I'm going mad because of it! A few sites I am making use the form, these are sites I created for paying clients so I need help ASAP! The form for the site I mentioned in the OP had worked initially but for some reason stopped (as far as I know the code hadn't changed at all). The only thing I can think of that may have made a difference was using Web Form Spam Protection (http://www.webformspamprotection.com/) but even then I made a back up (without Web Form Spam Protection) and it isn't working. Ho hum... :'( Quote Link to comment Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 Why don't you remove all the comment tags so we can see the actual code. Quote Link to comment Share on other sites More sharing options...
freenity Posted February 26, 2008 Share Posted February 26, 2008 Take a look at this function: http://gwphp.feudal-times.net/?p=4 Just use this function to send emails, it works tested. Quote Link to comment Share on other sites More sharing options...
niadev Posted February 26, 2008 Author Share Posted February 26, 2008 Sorry about that, here's the working (though too basic for my liking) code sans comments: <?php $errors = array(); if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} function recursive_array_check_header($element_value) { global $set; if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);} } } recursive_array_check_header($_REQUEST); if($set){$errors[] = "You cannot send an email header";} unset($set); if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";} $_REQUEST['email'] = trim($_REQUEST['email']); 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;}}}}}} } 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";} function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} 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,", ");} $message = build_message($_REQUEST); $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com"; $message = stripslashes($message); $subject = "FormToEmail Comments"; $headers = "From: " . $_REQUEST['email']; COPYRIGHT mail($my_email,$subject,$message,$headers); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form To Email PHP script from FormToEmail.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#ffffff" text="#000000"> <div> <center> <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b> <br>Your message has been sent <p><a href="<?php print $continue; ?>">Click here to continue</a></p> <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p> </center> </div> </body> </html> And the actual form: <form action="comments.php" method="post"> <table border="0" bgcolor="#ececec" cellspacing="5"> <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr> <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> <tr><td> </td><td><input type="submit" value="Send"><font face="arial" size="1"> <a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr> </table> </form> Freenity, please forgive my ignorance (noobieness?), but how should I add the code to the existing code i.e. how should it all look together? My brain is mush... Quote Link to comment Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 Let's make sure your mail function even works. Do a simple one line page <?php mail("youremail@email.com","subject","message","FROM: youremail@email.com"); ?> Replace youremail@email.com with your email address. If this doesn't work, check your server error log and see why. Quote Link to comment Share on other sites More sharing options...
niadev Posted February 27, 2008 Author Share Posted February 27, 2008 Sorry I took so long to reply freenity but I couldn't access my laptop until now. I did what you asked in the previous page and it worked, I got an email OK. Quote Link to comment Share on other sites More sharing options...
niadev Posted February 27, 2008 Author Share Posted February 27, 2008 Um, by my last post I meant I did the one line page revraz suggested and it worked. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 So now that's verified, verify all your variables. Before your mail function, echo each variable and see what they contain. It could be as simple as your FROM: address not being allowed by your mail server. Some mail servers require that the FROM: be a email address on your domain. Quote Link to comment Share on other sites More sharing options...
niadev Posted February 27, 2008 Author Share Posted February 27, 2008 Sorry (again), but I don't understand what you mean. Quote Link to comment Share on other sites More sharing options...
niadev Posted February 27, 2008 Author Share Posted February 27, 2008 Woohoo, I seem to have fixed it! With your advice revraz I figured out that I simply had to remove \"EPD QS Solutions"\, so the code now appears as follows: <?php $formurl = "http://www.epd-qs-solutions.com/comments.htm" ; $thankyouurl = "http://www.epd-qs-solutions.com/thankyou.htm" ; $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $name = $_POST['Name'] ; $telephone = $_POST['Telephone'] ; $email = $_POST['Email'] ; $companyname = $_POST['Company'] ; $comments = $_POST['Questions/comments'] ; $http_referrer = getenv( "HTTP_REFERER" ); $subject = "New comment from $name"; $message = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n\n" . "Name: $name\n" . "Email: $email\n" . "Telephone: $telephone\n" . "Company Name: $companyname\n\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; mail("nialldevlin@hotmail.com", $subject, $message, "FROM: service@noreply.epd-qs-solutions.com" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" ); header( "Location: $thankyouurl" ); exit ; ?> Thanks to everyone who posted with help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.