繁体   English   中英

PHP联系人表格不会从移动设备发送

[英]PHP Contact Form won't send from mobile device

我将该代码从某个网站上撤下来,以各种形式在我的网站上使用。 但是我今天有一个朋友给我发短信说:“嘿,我试图通过您的网站与您联系。” 哪一个在我的脑海中触发了警报……“您被捕了?” 因此,我进入了严格的测试模式,似乎唯一没有将我的表格通过电子邮件发送到我的帐户的情况是,当我通过手机提交表格时。 最糟糕的是,该网站将提交内容视为已发送表格。 没有错误信息。 这是代码:

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

请仔细阅读错误控制运算符

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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