I am currently working on a PHP-Formmailer. I`m completely new to PHP but I do have knowledge about HTML, CSS and Javascript. I would learn PHP starting with the basics and everything but I´ll be leaving the day after tomorrow so I would be very happy to see a quick solution :)
Mainly I´m concerned that the formmailer may be abused or that the e-mail will get spammed. Here´s what I did in HTML to prevent that:
- Give the input-element a special type(like number or email)
- Give the needed input-elements the value "required"
Make sure that search engines don´t find the website containing the form by adding
<meta name="robots" content="noindex" />
to the header.
Now here is my PHP:
<?php
// ======= config:
$mailTo = 'myEmail';
$mailFrom = '[email protected]';
$mailSubject = 'Formmailer of the homepage';
$returnPage = 'returnPage';
$returnErrorPage = 'errorPage';
$mailText = "";
// ======= configEND====
if(isset($_POST)) {
foreach($_POST as $name => $value) {
$mailText .= $name . ": " . htmlspecialchars($value) . "\n";
}
}
if(get_magic_quotes_gpc()) {
$mailtext = stripslashes($mailtext);
}
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom);
if($mailSent == TRUE) { header("Location: " . $returnPage);}
else { header("Location: " . $returnErrorPage);}
exit();
?>
Do you think that this is safe enough for a small homepage? Am I using htmlspecialchars()
correctly? Should I better use strip_tags()
?