PHP email form shooting blank emails

前端 未结 4 2086
[愿得一人]
[愿得一人] 2020-12-06 23:02

I put together a simple PHP email form for a website, but it keeps sending blank emails every so often. Most of the the fields are \"required\" and I was using a captcha sys

4条回答
  •  既然无缘
    2020-12-06 23:46

    You will want to do validation on your PHP.

    http://www.w3schools.com/php/php_form_validation.asp

    Basically you will want to do the following:

    Security

        
    

    Validation

    if (!empty($email)){
        //your code to send email
    }
    

    You could make it a little more complex if you want to check more than one thing.

    $fail_validation = FALSE;
    if (empty($email)){
       $fail_validation = TRUE;
    
    }
    if (empty($phone)){
       $fail_validation = TRUE;
    
    }
    if ($fail_validation == FALSE){
      //code to send mail goes here
    }
    

    Please note, this is very basic, and you may want to consider looking into some extra functions to secure the PHP. I would also suggest using a honeypot as an extra layer of security. https://stackoverflow.com/a/22103646/2547075

提交回复
热议问题