I bought a template, I was looking through it and have never seen this thing before & like its effect…
So I have a form http://www.ronisvonhelms.com/index.php
<form action="?email=attempt" method="post">
whose actrion is wierd, once the $_GET variable is set, here is the PHP script
<?php
if ($_GET["email"] == "attempt"){
$to='lurtnowski@gmail.com';
$messageSubject='RonisVonHelms Contact Form';
$confirmationSubject='Confirmation message subject';
$confirmationBody="Confirmation message body";
$email='';
$body='';
$displayForm=true;
$phone = $_POST['phone'];
if ($_POST){
$email=stripslashes($_POST['email']);
$body=stripslashes($_POST['body']);
// validate e-mail address
$valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
$crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$body);
if ($email && $body && $valid && !$crack){
if (mail($to,$messageSubject,$body,'From: '.$email."\r\n")
&& mail($email,$confirmationSubject,$confirmationBody.$body,'From: '.$to."\r\n")){
?>
<?php header( 'Location: ?v=success' ) ; ?>
<?php
echo '<p>'.htmlspecialchars($body).'</p>';
}else{ // the messages could not be sent
?>
<?php header( 'Location: ?v=servererror' ) ; ?>
<?php
}
}else if ($crack){ // cracking attempt
?>
<?php header( 'Location: ?v=hacker' ) ; ?>
<?php
}else{ // form not complete
?>
<?php header( 'Location: ?v=fail' ) ; ?>
<?php
}
}
}
?>
Thanks
I tried to test it, but am, not getting the email, is there something wrong with the script?
eregi is antiquated and unlikely to be supported much longer
just running stripslashes on the email and body are not really confirming that either is valid
the validation for email is very poor - 99% of possible email addresses will be rejected as invalid - using the validation filter would be a lot better
also are you sure your hosting still supports using mail() as many now want you to use something more secure
I guess so.
mail() is just a wrapper around console command, so you have to check lots of factors to make it secure (otherwise someone can execute something bad on your system)
PHPMailer makes all that checks for you and also it allows you to use SMTP server (eg. smtp.gmail.com, what is more secure by default)
It is if you use SMTP - some web gosts disable mail() from sending outside of the server and insist on you using SMTP for email to be sent to others as this makes their overall hosting environment more secure and their mail servers are less likely to be blacklisted as the origin of the emails is clearly identified in the wrapper around the email.