Wesley Smith
Wesley Smith

Reputation: 19571

contents of text area not posting

I have a form located at https://pnrbuilder.com/_popups/feedback_popup.html

The form uses post to pass the input to a php page which sends an email with the contents of the post then redirects the user.

The input fields work fine but the textarea content doesnt make it to the email.

Any idea what Im doing wrong?

the PHP Page:

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "[email protected]";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";


/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$EmailAddress = $_POST['EmailAddress'] ;
$IssueType = $_POST['IssueType'] ;
$Comments = $_POST['Comments'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
        return true;
    }
    else {
        return false;
    }
}


// If email injection is detected, redirect to the error page.
if ( isInjected($EmailAddress) ) {
header( "Location: $error_page" );
}

// If we passed the previous test, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email, [email protected]", "Feedback",
  $EmailAddress, $IssueType, $Comments );
header( "Location: $thankyou_page" );
}
?>

If I put the below at the top of my php page it DOES echo out the contents of the textarea

echo $_POST["EmailAddress"];
echo $_POST["IssueType"];
echo $_POST["Comments"];

Upvotes: 2

Views: 338

Answers (2)

Ja͢ck
Ja͢ck

Reputation: 173572

Sending email

You're passing the wrong parameters to mail():

mail( "$webmaster_email, [email protected]", "Feedback", $EmailAddress, $IssueType, $Comments);

That should be:

$contents = <<<EOM
Email: $emailAddress

Issue type: $IssueType

Comments:
$Comments
EOM;

mail( "$webmaster_email, [email protected]", "Feedback", $contents);

Email validation

Secondly, you should use proper email validation:

$emailAddress = filter_input(INPUT_POST, 'EmailAddress', FILTER_VALIDATE_EMAIL);
if ($emailAddress === false) {
    header( "Location: $error_page" );
}

Upvotes: 1

Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Please, check out the correct form of PHP's mail function :

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Reference : http://php.net/manual/en/function.mail.php


Message is supposed to be the 3rd parameter, nope?

What you've written is :

mail( "$webmaster_email, [email protected]", "Feedback",
  $EmailAddress, $IssueType, $Comments );

Rewrite it like this :

$messageBody = "Comments : ".$Comments." Issue : ".$IssueType;
mail("$webmaster_email, [email protected]", "Feedback", $messageBody);

Just wanted it to see if there was something wrong with the $_POST, but I guess my code above will fix the issue (just bundle up all your data in a $messageBody var and pass it on to the mail function).

Upvotes: 2

Related Questions