Jump to content

[SOLVED] PHP form help required


lexie

Recommended Posts

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.

Link to comment
Share on other sites

<?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" );

}

 

?>

 

Link to comment
Share on other sites

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 />');

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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); }

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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" ); } ?>

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.