Code: Select all
<?php
function checkUserEmail($email){
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
return TRUE;
}
else{
return FALSE;
}
}
if(isset($_REQUEST['email']) && isset($_REQUEST['name']) && isset($_REQUEST['comment'])){
if(checkUserEmail($_REQUEST['email'])){
echo "<p>An error occurred while processing your comment!</p>";
echo "<p>Are you sure than you entered everything correctly? Or that you are not making any unnecessary inputs?</p>";
}
else{
$headers = "From: " . $_REQUEST['uname'] . "\r\n" . "Email: " . $_REQUEST['email'] . "\r\n" . "Website: " . $_REQUEST['url'];
mail("myemailadd@mywebsite.com", "TEST Website Comment", wordwrap($_REQUEST['comment'], 70), $headers);
echo "<p>Your comment has been sent.</p>";
}
}
else{
//CHECK OUT THIS ECHO AND action ATTRIBUTE
echo "<form method='post' action='email.php' class='pMirror'>
<p>Fields marked with an asterisk (*) are required.</p>
Name*: <input type='text' name='uname' id='uname' /><br />
Email*: <input type='text' name='email' id='email' /><br />
Website: <input type='test' name='url' id='url' /><br />
Comment*:<br />
<textarea name='comment' id='comment' rows='10' cols='56'></textarea><br />
<input type='submit'>
</form>";
}
?>- First I tried to create a separate php file for the code above (named, say, foo.php). In my email page (say, email.php) I embedded foo.php using a <?php include("foo.php"); ?> statement. It did not work as expected. All that happened is that I got to a "bare bones" page of the form (i.e. no formatting, etc. Well, I know it is because the browser loaded foo.php)
- Then I tried to change the action attribute at foo.php so that is says action='email.php' . Still doesn't work but I got redirected to to email.php . (As users will be entering info from email.php, the unaquainted will get the feeling that the page got "refreshed"). Again, for reasons obvious to me.
- Finally, I tried to embed the code itself (i.e., I copy-pasted) of foo.php to email.php, the way W3schools did it. Still to no avail.