简体   繁体   中英

PHP Contact Form won't send from mobile device

I pulled this code off some site to use in various forms on my website. But I had a friend text me today saying "hey I tried to contact you through your website." Which set off an alarm in my head... "you TRIED?" So I went into heavy test mode, and it seems the only thing my forms don't get emailed to my account is when I submit them from my phone. The worst part is that the site treats the submit as if the form was sent. There is no error message. Here is the code: `

        $email_to = "info@optiprintdesign.com";
        $email_subject = "Contact Form Message - Opti Print and Design";


        function died($error) {
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }

        if(!isset($_POST['username']) ||
            !isset($_POST['usercompany']) ||
            !isset($_POST['email']) ||
            !isset($_POST['userphone']) ||
            !isset($_POST['usersite']) ||
            !isset($_POST['userlocation']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        }

        $username = $_POST['username']; 
        $usercompany = $_POST['usercompany']; 
        $email_from = $_POST['email']; 
        $userphone = $_POST['userphone']; 
        $usersite = $_POST['usersite'];    
        $userlocation = $_POST['userlocation'];         
        $comments = $_POST['comments'];

        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$username)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      }
      if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";

        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }

        $email_message .= "Name: ".clean_string($username)."\n";
        $email_message .= "Company: ".clean_string($usercompany)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Phone: ".clean_string($userphone)."\n";
        $email_message .= "Website: ".clean_string($usersite)."\n";
        $email_message .= "Location: ".clean_string($userlocation)."\n";    
        $email_message .= "Comments: ".clean_string($comments)."\n";


    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>

Please read up on Error Control Operators

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM