Hello everyone. My task is to create a 'Contact Us' form where the users can type a message, click a button, and it will send it to my e-mail.
What I have:
four files:
error_message.html -- 'Oops, something went wrong' form.
feedback_form.html -- This contains my actual form.
send_mail.php -- This is the action which would send the email.
thank_you.html -- Confirmation of the send.
Here is the feedback_form.html
<div class="main_body">
<p>Send Us Your Feedback!</p>
<form action="send_mail.php" method="post">
<table>
<tr>
<td>Email Adress:</td>
<td>
<input type="text" name="email_address" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>Comments:</td>
<td>
<textarea rows="10" cols="50" name="comments"></textarea>
</td>
</tr>
<tr><td> </td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
</div>
Now, What I wanted to happen, was to run the send_mail.php:
<?php
$webmaster_email = "Myemail@mail.com";
$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;
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 (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}
elseif (empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}
else {
mail( "$webmaster_email", "Feedback Form Results",
$comments, "From: $email_address" );
header( "Location: $thankyou_page" );
}
?>
But, instead, what happens is that when I click submit on the first form, I end up downloading the send_mail.php file.
What is my problem? And what is the proper approach? Thanks to all.
NOTE: I had downloaded this as a template from a website:
http://www.quackit.com/php/tutorial/php_mail_configuration.cfm[
^]