0

我从某个网站上提取了这段代码,以便在我的网站上以各种形式使用。但今天我有一个朋友给我发短信说“嘿,我试图通过你的网站联系你。” 这在我脑海中引发了警报……“你试过了吗?” 所以我进入了繁重的测试模式,我的表格似乎唯一没有通过电子邮件发送到我的帐户的事情是当我通过手机提交它们时。最糟糕的部分是该站点将提交视为已发送表单。没有错误信息。这是代码:`

        $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); 
    ?>
4

1 回答 1

0

请阅读错误控制运算符

PHP 支持一种错误控制运算符:at 符号 (@)。当附加到 PHP 中的表达式时,该表达式可能生成的任何错误消息都将被忽略。

于 2013-08-07T17:32:06.347 回答