javascript - what improvements do i need to make to my form submission (for email) to stop the spam i am receiving and make my form more secure? -


every morning @ 10:53am hit 1-2 blank emails sort of entity using send.php file.

i know result of php send file on website, dont have knowledge of php. spent lot of time several weeks ago looking clear cut information telling me how setup input form php send , got far. know there absolutely glaringly obvious security holes in code.

i know doing wrong on form lock down dont hit spam anymore.

i have javascript honeypot, input field if hidden field gets selected changes value true false , form no longer submit form instead give user alert saying have submitted form, , page reloads (probably not great of solution).

i went ahead , replaced email some@email.com

<?php   $sname = $_post['name'];   $slastname = $_post['last-name'];   $semail = $_post['email'];   $semailconfirm = $_post['confirm-email'];   $sphone = $_post['phone-number'];   $smessage = filter_var($_post['message'], filter_sanitize_string );      $formerrors = false;      if ($sname === '') :     echo "<div>sorry, first name required field</div>";   endif; //input field empty    if (!(preg_match('/[a-za-z]+/', $sname)) ) :     echo "<div>sorry, first name doesnt follow allowed pattern</div>";   endif; //pattern doesnt match    if ($slastname === '') :     echo "<div>sorry, last name required field</div>";   endif; //input field empty    if (!(preg_match('/[a-za-z]+/', $slastname)) ) :     echo "<div>sorry, last name doesnt follow allowed pattern</div>";   endif; //pattern doesnt match     if ($semail === '') :     echo "<div>sorry, email required field</div>";   endif; //input field empty    if ($semailconfirm !== $semail) :     echo "<div>sorry, emails must match</div>";   endif; //input field empty    if ($smessage === '') :     echo "<div>sorry, message has no content</div>";   endif; //input field empty      if (!($formerrors)) :     $to       = "some@email.com";     $subject  = "from $sname $slastname -- $semail -- $sphone";     $message  = "$sname filled out form";      $replyto  = "from: $semail \r\n".                 "reply-to: some@email.com \r\n";      if (mail($to, $subject, $smessage)):       $msg = "thanks filling out contact form";     else:       $msg = "problem sending message";     endif; //mail form data    endif; //check errors   ?> 

the email every day says

from -- --

and doesnt have in text body

you never set $formerrors so

 if ($sname === '') :     echo "<div>sorry, first name required field</div>";   endif; //input field empty 

and other checks output error still process form.

try:

 if ($sname === '') :     echo "<div>sorry, first name required field</div>";     $formerrors = true;   endif; //input field empty 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -