lexie Posted November 11, 2009 Share Posted November 11, 2009 Hi all! Apologies in advance for having to message the forum for help. I know you must get a lot of questions. I've tried everything I can think of & haven't had any luck so this is my last resort. Please keep in mind I'm new to php. I have created a html feedback form & the associated php form. Includes reCaptcha. The form is online & working. The required details must be filled in works. The reCaptcha works. The submit button works. The 'thankyou' page is displayed. The form is recieved in my email from the email address entry required on the form. However, there's no actual email content. I really have no idea what I've done wrong. Its a commercial website host & the do support PHP. Any help would be greatly appreciated! THANKS I'm more than happy to post the code if it would help. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/ Share on other sites More sharing options...
mikesta707 Posted November 11, 2009 Share Posted November 11, 2009 code? We would need that to be of help Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955360 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 <?php $firstname = $_REQUEST['firstname'] ; $lastname = $_REQUEST['lastname'] ; $companyname = $_REQUEST['companyname'] ; $street1 = $_REQUEST['street1'] ; $suburb1 = $_REQUEST['suburb1'] ; $state1 = $_REQUEST['state1'] ; $postcode1 = $_REQUEST['postcode1'] ; $street2 = $_REQUEST['street2'] ; $suburb2 = $_REQUEST['suburb2'] ; $state2 = $_REQUEST['state2'] ; $postcode2 = $_REQUEST['postcode2'] ; $phone = $_REQUEST['phone'] ; $mobile = $_REQUEST['mobile'] ; $fax = $_REQUEST['fax'] ; $email = $_REQUEST['email'] ; $span = $_REQUEST['span'] ; $baysize = $_REQUEST['baysize'] ; $length = $_REQUEST['length'] ; $eaveheight = $_REQUEST['eaveheight'] ; $cladding = $_REQUEST['cladding'] ; $slidingdoors = $_REQUEST['slidingdoors'] ; $rollerdoors = $_REQUEST['rollerdoors'] ; $padoors = $_REQUEST['padoors'] ; $windows = $_REQUEST['windows'] ; $skylights = $_REQUEST['skylights'] ; $roofventilators = $_REQUEST['roofventilators'] ; $partitionwalls = $_REQUEST['partitionwalls'] ; $additionalcomments = $_REQUEST['additionalcomments'] ; if ( preg_match( "/[\r\n]/", $firstname ) || preg_match( "/[\r\n]/", $lastname ) || preg_match( "/[\r\n]/", $companyname ) || preg_match( "/[\r\n]/", $street1 ) || preg_match( "/[\r\n]/", $suburb1 ) || preg_match( "/[\r\n]/", $state1 ) || preg_match( "/[\r\n]/", $postcode1 ) || preg_match( "/[\r\n]/", $street2 ) || preg_match( "/[\r\n]/", $suburb2 ) || preg_match( "/[\r\n]/", $state2 ) || preg_match( "/[\r\n]/", $postcode2 ) || preg_match( "/[\r\n]/", $phone ) || preg_match( "/[\r\n]/", $mobile ) || preg_match( "/[\r\n]/", $fax ) || preg_match( "/[\r\n]/", $email ) || preg_match( "/[\r\n]/", $span ) || preg_match( "/[\r\n]/", $baysize ) || preg_match( "/[\r\n]/", $length ) || preg_match( "/[\r\n]/", $eaveheight ) || preg_match( "/[\r\n]/", $slidingdoors ) || preg_match( "/[\r\n]/", $rollerdoors ) || preg_match( "/[\r\n]/", $padoors ) || preg_match( "/[\r\n]/", $windows ) || preg_match( "/[\r\n]/", $skylights ) || preg_match( "/[\r\n]/", $roofventilators ) || preg_match( "/[\r\n]/", $partitionwalls ) || preg_match( "/[\r\n]/", $additionalcomments ) ) { header( "Location: http://www.tastechbuildings.com.au/error.html" ); } require_once('recaptchalib.php'); $privatekey = "6Lf-TAkAAAAAAFgCsu6MLK3qp-Wd3BHxo9rlTYjG"; $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. Go back via your browser and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { mail( "info@tastechbuildings.com.au", "Online Quotation Request", $message, "From: $email" ); header( "Location: http://www.tastechbuildings.com.au/thankyou.html" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955363 Share on other sites More sharing options...
mikesta707 Posted November 11, 2009 Share Posted November 11, 2009 you never set the variable $Message. you have to define it as something. By the way, if you set error reporting to E_ALL while developing, it will save you a lot of trouble error_reporint(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955364 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 Thanks Mike. As I said, I'm new to php. Not sure what exactly I have to include in the code re: $Message. Could you please give an example. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955389 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 Hi all. Is anyone able to help? I'm new to PHP & trying to learn. I'm not sure what I have to include re: $Message. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955809 Share on other sites More sharing options...
mrMarcus Posted November 11, 2009 Share Posted November 11, 2009 haven't looked at your code yet .. i just put it in [ code ] tags to make it easier to read. <?php $firstname = $_REQUEST['firstname'] ; $lastname = $_REQUEST['lastname'] ; $companyname = $_REQUEST['companyname'] ; $street1 = $_REQUEST['street1'] ; $suburb1 = $_REQUEST['suburb1'] ; $state1 = $_REQUEST['state1'] ; $postcode1 = $_REQUEST['postcode1'] ; $street2 = $_REQUEST['street2'] ; $suburb2 = $_REQUEST['suburb2'] ; $state2 = $_REQUEST['state2'] ; $postcode2 = $_REQUEST['postcode2'] ; $phone = $_REQUEST['phone'] ; $mobile = $_REQUEST['mobile'] ; $fax = $_REQUEST['fax'] ; $email = $_REQUEST['email'] ; $span = $_REQUEST['span'] ; $baysize = $_REQUEST['baysize'] ; $length = $_REQUEST['length'] ; $eaveheight = $_REQUEST['eaveheight'] ; $cladding = $_REQUEST['cladding'] ; $slidingdoors = $_REQUEST['slidingdoors'] ; $rollerdoors = $_REQUEST['rollerdoors'] ; $padoors = $_REQUEST['padoors'] ; $windows = $_REQUEST['windows'] ; $skylights = $_REQUEST['skylights'] ; $roofventilators = $_REQUEST['roofventilators'] ; $partitionwalls = $_REQUEST['partitionwalls'] ; $additionalcomments = $_REQUEST['additionalcomments'] ; if ( preg_match( "/[\r\n]/", $firstname ) || preg_match( "/[\r\n]/", $lastname ) || preg_match( "/[\r\n]/", $companyname ) || preg_match( "/[\r\n]/", $street1 ) || preg_match( "/[\r\n]/", $suburb1 ) || preg_match( "/[\r\n]/", $state1 ) || preg_match( "/[\r\n]/", $postcode1 ) || preg_match( "/[\r\n]/", $street2 ) || preg_match( "/[\r\n]/", $suburb2 ) || preg_match( "/[\r\n]/", $state2 ) || preg_match( "/[\r\n]/", $postcode2 ) || preg_match( "/[\r\n]/", $phone ) || preg_match( "/[\r\n]/", $mobile ) || preg_match( "/[\r\n]/", $fax ) || preg_match( "/[\r\n]/", $email ) || preg_match( "/[\r\n]/", $span ) || preg_match( "/[\r\n]/", $baysize ) || preg_match( "/[\r\n]/", $length ) || preg_match( "/[\r\n]/", $eaveheight ) || preg_match( "/[\r\n]/", $slidingdoors ) || preg_match( "/[\r\n]/", $rollerdoors ) || preg_match( "/[\r\n]/", $padoors ) || preg_match( "/[\r\n]/", $windows ) || preg_match( "/[\r\n]/", $skylights ) || preg_match( "/[\r\n]/", $roofventilators ) || preg_match( "/[\r\n]/", $partitionwalls ) || preg_match( "/[\r\n]/", $additionalcomments ) ) { header( "Location: http://www.tastechbuildings.com.au/error.html" ); } require_once('recaptchalib.php'); $privatekey = "6Lf-TAkAAAAAAFgCsu6MLK3qp-Wd3BHxo9rlTYjG"; $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. Go back via your browser and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { mail( "info@tastechbuildings.com.au", "Online Quotation Request", $message, "From: $email" ); header( "Location: http://www.tastechbuildings.com.au/thankyou.html" ); } ?> EDIT: k, as mike said, you have not set $message. will have to assume you have <textarea name="message"></textarea> in your form? anyways, let's assume you have something in your form with the name "message". you will want to set this $variable like the others (well, almost). try this (add it with the rest of your variables): $message = wordwrap (nl2br ($_POST['message']), 70, '<br />'); Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955817 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 Thanks. I noticed that option after I had already posted it! Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955818 Share on other sites More sharing options...
mrMarcus Posted November 11, 2009 Share Posted November 11, 2009 made edit to my post .. please have a look. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955825 Share on other sites More sharing options...
mrMarcus Posted November 11, 2009 Share Posted November 11, 2009 instead of that ghastly if (preg_match(...)) you got there, here's a simple function that will do the same: <?php function match_r_n ($arr) { if (is_array ($arr)) { foreach ($arr as $v) { if (preg_match ("/[\r\n]/", $v)) { return true; break; } else { return false; } } } else { return false; } } ?> usage: <?php if (match_r_n ($_REQUEST)) { header ('Location: http://www.tastechbuildings.com.au/error.html'); exit (0); } ?> EDIT: forgot to return false on no match found. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955830 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 Ok awesome, so that's a quick way of doing it for all the categories rather than my crazy long version. Thanks. Is there a way to check if this function is working properly? Just to make sure I'm putting it in correctly, I'm replacing mine with: <?php function match_r_n ($arr) { if (is_array ($arr)) { foreach ($arr as $v) { if (preg_match ("/[\r\n]/", $v)) { return true; break; } else { return false; } } } else { return false; } } if (match_r_n ($_REQUEST)) { header ('Location: http://www.tastechbuildings.com.au/error.html'); exit (0); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955840 Share on other sites More sharing options...
mrMarcus Posted November 11, 2009 Share Posted November 11, 2009 normally, i create a file to be included that holds all my functions, and place it at the top of my scripts, ie: <?php include ('/path/to/functions.php'); ?> and place the function within that file. that way, your functions can be used by multiple scripts which is the way you want to go. then, in place of where you have you current "if (preg_match (blah blah blah))", put: if (match_r_n ($_REQUEST)) { header ('Location: http://www.tastechbuildings.com.au/error.html'); exit (0); } just make sure you replace the current code to avoid redundancy. it doesn't have to go in that exact spot, but it's ok there. EDIT: did you get the $message working to email? Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955844 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 As for the topic in question, the only text area I have is 'Additional Comments'. <textarea name="additionalcomments" id="additionalcomments" cols="70" rows="4" tabindex="300"></textarea> in my form & $additionalcomments = $_REQUEST['additionalcomments'] ; in my php. None of the text fields (or the text area) show up in the email apart from the actual 'Subject' & the 'From' email. ??? I'm just trying to get my head around this properly & learn the language. I think what I may have done wrong (maybe?!) is not enter the correct info. I could be way off, I'm not sure. Is the following what I need to do? <?php mail( "info@tastechbuildings.com.au", "Online Quotation Request", $firstname, $lastname, $companyname etc. "From: $email" ); header( "Location: http://www.tastechbuildings.com.au/thankyou.html" ); } ?> With regards to the the hijacking code. What you said makes sense. Thanks for the tip re: having a separate function file. I'm giving it a go now. Will let you know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955865 Share on other sites More sharing options...
lexie Posted November 11, 2009 Author Share Posted November 11, 2009 Ok, so that's not my answer because it didn't work. Instead I got error message: "(reCAPTCHA said: " . $resp->error . "); } else { mail( "info@tastechbuildings.com.au", "Online Quotation Request", $firstname, $lastname, $companyname, $street1, $suburb1, $state1, $postcode1, $street2, $suburb2, $state2, $postcode2, $phone, $mobile, $fax, $email, $span, $baysize, $length, $eaveheight, $cladding, $slidingdoors, $rollerdoors, $padoors, $windows, $skylights, $roofventilators, $partitionwalls, $addtionalcomments, "From: $email" ); header( "Location: http://www.tastechbuildings.com.au/thankyou.html" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955881 Share on other sites More sharing options...
mrMarcus Posted November 12, 2009 Share Posted November 12, 2009 the mail() function does not like that many arguments. keep it to: <?php mail ($to, $subject, $body, $headers); ?> these are just example variables. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955898 Share on other sites More sharing options...
mrMarcus Posted November 12, 2009 Share Posted November 12, 2009 if you are looking to get all of those POSTED/REQUESTED variables in the message of the email, you can try this: <?php $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html;' . "\r\n" . 'Content-Transfer-Encoding: 8bit' . "\r\n" . 'From: ' . $from . "\r\n"; $message = wordwrap (implode (', ', $_REQUEST), 70, '<br />'); mail ('info@tastechbuildings.com.au', 'Online Quotation Request', $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955904 Share on other sites More sharing options...
lexie Posted November 12, 2009 Author Share Posted November 12, 2009 All is working! Thanks so much for your help! Greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955921 Share on other sites More sharing options...
lexie Posted November 12, 2009 Author Share Posted November 12, 2009 On another note, are there any other script functions you would reccomend? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/181063-solved-php-form-help-required/#findComment-955923 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.