I wonder if somebody can help me with 2 simple problems with my form.
Here is the html form:
- Code: Select all
<form action="send_mail.php" method="post">
<div style="height:30px;"><input class="input_txt2" value="Name: " name="Name" type="text" /></div>
<div style="height:30px;"><input class="input_txt2" value="Email: " name="Email" type="text" /></div>
<div style="height:30px;"><input class="input_txt2" value="Subject: " name="Subject" type="text" /></div>
<div><textarea class="text_area2" cols="32" rows="5" name="Comments">Message: </textarea></div>
<input class="submit2" name="reset" type="submit" value="Submit" />
</div>
</form>
Here is the PHP script with my email blanked:
- Code: Select all
<?php
$feedback_page = "contact_us.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
$To = "support@mycorrectdomain.com";
$Email = $_REQUEST['Email'] ;
$Comments = $_REQUEST['Comments'] ;
$Name = $_REQUEST['Name'] ;
$Subject = $_REQUEST['Subject'] ;
$Header = "From: $Name <$Email>" ;
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 the user tries to access this script directly, redirect them to the feedback form,
if (!isset($Email)) {
header( "Location: $feedback_page" );
}
// If the form fields are empty, redirect to the error page.
elseif (empty($Email) || empty($Name) || empty($Subject) || empty($Comments) ) {
header( "Location: $error_page" );
}
// If email injection is detected, redirect to the error page.
elseif ( isInjected($Email) ) {
header( "Location: $error_page" );
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
$send_contact=mail($To,$Subject,$Comments,$Header);
header( "Location: $thankyou_page" );
}
?>
Email arrives ok.
Problem no 1: The From field shows MY domain mail server as the sender.
Problem no 2: Probably part of problem 1, the Name field isn't sent anywhere either.
I'm sure it is a dead simple fix, can anybody help?

