Log in

View Full Version : php form problem What is the code to add this extra security to the form?



kplusonline
08-26-2014, 04:01 PM
I have created a form using the below php. I have a couple of issues...

1.The form seems to be working except it is not showing the sender's name/email in the 'from' section... how can I get it to show the sender's email?

2.Is there some sort of coding I can add to help prevent spam from coming through? I saw once on a form where it asked a question and below it said 'so we know you are not a machine'. What is the code to add this extra security to the form?

Any assistance is greatly appreciated.

Here is the php the form is using....


<?php

$EmailFrom = "";
$EmailTo = "nina@make-upbynina.com";
$Subject = "Make-up Inquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.make-upbynina.com/form-reply.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Bionic
09-02-2014, 05:01 PM
these links will help you figure out how to place a "from" into the mail() function your code there for the mail() function for FROM is not correct
http://php.net/manual/en/function.mail.php
http://www.w3schools.com/php/func_mail_mail.asp


$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);

I think you need to remove the "<>" from your header section in the mail() function

and to add a anti spam feature get recaptcha. its really easy and made by Google. Otherwise you can add a field to your form "what is 2+2" and make sure that on your submit that it is $_POST['thatField'] is set to 4

http://www.google.com/recaptcha/intro/