Sandstone-Shadow
A chickadee in love with the sky
- Pronoun
- she/her
So I tried making a feedback form that will send a message to my email address. I used this site and the following pages on it to put it together, but I'm having a tough time understanding it.
First, about the thing so that the error messages, etc. aren't cached: is the date set to December of 1998 so that the message is always expired, and therefore won't save and appear before someone's submitted the form?
Second, I'm not sure if I did the email injection prevention part right, the first part. I pretty much copied that straight from the tutorial and left it because I wasn't sure what to do with it.
And third, I'm not sure what I did, but the form doesn't work right now. I think it had something to do with adding the "name" and "version" fields in the sending part, but I don't know what I did wrong.
Here's my code:
What do you think?
First, about the thing so that the error messages, etc. aren't cached: is the date set to December of 1998 so that the message is always expired, and therefore won't save and appear before someone's submitted the form?
Second, I'm not sure if I did the email injection prevention part right, the first part. I pretty much copied that straight from the tutorial and left it because I wasn't sure what to do with it.
And third, I'm not sure what I did, but the form doesn't work right now. I think it had something to do with adding the "name" and "version" fields in the sending part, but I don't know what I did wrong.
Here's my code:
Code:
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$name = $_REQUEST['name'] ;
$version = $_REQUEST['version'] ;
if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
?>
<?PHP include('top.txt');?>
<h1>Error</h1>
<p>
There is a problem with the content of the "name" or "email" field. Please make sure that this information is formatted correctly. Please press the BACK
button in your browser and try again.
</p>
<?PHP include('bottom.txt');?>
<?php
}
if (!isset($_REQUEST['email'])) {
?>
<?PHP include('top.txt');?>
<h1>Ask a Question about a Pokémon Game</h1>
<p>Have a question about a Pokémon game? Ask any sort of game question here! I'll find the answer and post a response here.</p>
<p>Please specify what game the question is about.</p>
<form method="post" action="sendmail.php">
Name: <input name="name" type="text" /><br />
Email: <input name="email" type="text" /><br />
Version: <input name="version" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
<?PHP include('bottom.txt');?>
<?php
}
elseif (empty($email) || empty($message)) {
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
?>
<?PHP include('top.txt');?>
<h1>Error</h1>
<p>
Oops, it appears you forgot to enter either your
email address or your message. Please press the BACK
button in your browser and try again.
</p>
<?PHP include('bottom.txt');?>
<?php
}
else {
mail( "absolsmoonlitcave@gmail.com", "New Gaming Question",
"$version\n\n$message", "From: $name <$email>" );
?>
<?PHP include('top.txt');?>
<h1>thanks</h1>
<p>
it worked! thanks.
</p>
<?PHP include('bottom.txt');?>
<?php
}
?>
What do you think?