Hi
I’m a beginner with PHP and using the code below from a basic tutorial to use on a website. I’m wondering if it is secure enough and should work ok?
Many thanks for any advice,
Emma
CONTACT PAGE HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"><title>What are you thinking?</title>
<meta content="php, contact, form, thinking" name="keywords">
<meta content="Contact us and let us know if we can help you out further." name="description">
<style>
input, textarea {
padding: 5px;
margin: 10px;
font-family: Cambria, Cochin, serif;
font-size: medium;
font-weight: bold;
outline: none;
}
p {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}
input[type=text], textarea {
width: 350px;
background-color: #DDEDFF;
border: 1px solid #97C9FF;
}
input[type=submit] {
width: 100px;
background-color: #669900;
border: 1px solid #336600;
font-size: large;
color: #FFFFFF;
}
input[type=submit]:hover {
background-color: #78B300;
cursor: pointer;
}
input[type=submit]:active {
background-color: #4A6F00;
}
h1 {
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: 2.1em;
color: #3399FF;
}
body {
padding: 10px;
background-color: #F4F4F4;
}
</style>
</head>
<body>
<h1>What are you thinking?</h1>
<form action="mailer.php" method="POST">
<div>
<p>Name</p>
<input name="name" type="text"> <br> </div>
<div>
<p>E-Mail (Optional)</p>
<input name="email" type="text">
<br>
</div>
<div>
<p>Comment</p>
<textarea cols="30" name="comment" rows="9"></textarea>
<br> </div>
<div>
<input name="submit" type="submit" value="Send!"> </div>
</form>
</body>
</html>
PHP PAGE:
[php]<?php
if(isset($_POST[‘submit’])) {
$to = "[email protected]";
$subject = “What are you thinking submission!”;
// data the visitor provided
$name_field = filter_var($_POST[‘name’], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST[‘email’], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST[‘comment’], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";
// …and away we go!
mail($to, $subject, $body);
// redirect to confirmation
header(‘Location: confirmation.htm’);
} else {
// handle the error somehow
}
?>
[/php]
CONFIRMATION PAGE:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Great Success!</title>
<meta content="php, contact, form, thinking" name="keywords">
<meta content="Great success!" name="description">
<style>
p {
font-family: Cambria, Cochin, serif;
font-size: large;
margin-bottom: -5px;
}
h1 {
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: xx-large;
color: #3399FF;
}
body {
padding: 10px;
background-color: #F4F4F4;
}
</style>
</head>
<body>
<h1> </h1>
<h1>Thank You!</h1>
<p>We've received your feedback, and we will get back to you soon.</p>
</body>
</html>