Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件()服务_Php - Fatal编程技术网

PHP邮件()服务

PHP邮件()服务,php,Php,所以我对PHP还比较陌生,一直在构建一个订单表单,可以在发送前验证字段,以及检查垃圾邮件。 通过测试,下面的代码可以很好地返回错误等,但是当我输入正确的信息时,我不会收到任何电子邮件。 在我添加Vaildation部分之前,它工作得很好,但是现在我遇到了上面的问题。再一次,我还在学习,所以任何指点都很好,谢谢 <?php function spamcheck($field) { $field=filter_var($field, FILTER_SANITIZE_EMAI

所以我对PHP还比较陌生,一直在构建一个订单表单,可以在发送前验证字段,以及检查垃圾邮件。 通过测试,下面的代码可以很好地返回错误等,但是当我输入正确的信息时,我不会收到任何电子邮件。 在我添加Vaildation部分之前,它工作得很好,但是现在我遇到了上面的问题。再一次,我还在学习,所以任何指点都很好,谢谢

<?php
    function spamcheck($field) {
      $field=filter_var($field, FILTER_SANITIZE_EMAIL);
      if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
        return TRUE;
      } else {
        return FALSE;
      }
    }
    ?>
    <?php
    if (!isset($_POST["submit"])) {
      ?>

然后将表格放在上面,这样当按下sumbit按钮时,表格就不会消失。这不会给我任何错误,但提交后仍然不会发送电子邮件

我建议您使用电子邮件库发送电子邮件,因为不同的服务器可能支持或不支持许多不同的参数。如果您的邮件结果是“确定”,但您没有收到电子邮件,那么您的邮件标题信息可能有问题。谢谢,我会考虑使用它。至于这一点,当我添加验证部分时,我没有更改任何标题信息,这让我很困惑,为什么我没有收到电子邮件,我真的不知道怎么回事。您的代码可能有问题,或者邮件内容的一部分可能会损坏邮件。尝试设置错误报告全部;在你的代码之前,看看代码是否有任何问题。我用它来反映你的使用情况,但仍然没有收到任何电子邮件
<?php } 
else 
{
    if (isset($_POST["email"])) {
        $mailcheck = spamcheck($_POST["email"]);
        if ($mailcheck==FALSE) {
            echo "Invalid input";
            }
//field vailation
        else {
            if (isset($_POST['submit'])) {
                $errors = array();
                if (!empty($_POST["fullname"])) {
                    $fullname = $_POST["fullname"];
                    $pattern = "/^[a-zA-Z0-9\_]{2,20}/";
                    if (preg_match($pattern,$fullname)){ $fullname = $_POST["fullname"];}
                        else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
                        } else {$errors[] = 'You forgot to enter your First Name.';}

                if (!empty($_POST["contact"])) {
                    $contact = $_POST["contact"];
                    $pattern = "/^[0-9\_]{6,20}/";
                    if (preg_match($pattern,$contact)){ $contact = $_POST["contact"];}
                        else{ $errors[] = 'Your contact number can only be numbers, or is too short';}
                        } else {$errors[] = 'You forgot to enter your contact number.';}
            }
//end vaildation
            else{
                $fullname = $_POST["fullname"];
                $email = $_POST["email"];
                $address = $_POST["address"];
                $address2 = $_POST["address2"];
                $town = $_POST["town"];
                $postcode = $_POST["postcode"];
                $contact = $_POST["contact"];
                $shipping = $_POST["shipping"];
                $extra = $_POST["extra"];
                $extra = wordwrap($extra, 70);

                $message = '
                Full Name: ' . $fullname . '
                Delivery Address: ' . $address . '
                Delivery Address2: ' . $address2 . '
                Town/City: ' . $town . '
                Postal Code: ' . $postcode . '
                Contact: ' . $contact . '
                Email Address: ' . $email . '
                Special instructions: ' . $extra . '
                Shipping Method: ' . $shipping . '
                ';
                mail("myemail@myaddress.com","Order form",$message,"email: $email\n");
                echo 
                "<html>
                <body><br><br>
                Order successful, we will be in contact shortly<br>
                </body>
                </html>";
            }
        }
    }
}
?>

<?php 
if (isset($_POST['submit'])) {
    if (!empty($errors)) { 
        echo '<hr /><h3>The following occurred:</h3><ul>'; 
        foreach ($errors as $msg) { echo '<li>'. $msg . '</li>';}
        echo '</ul><h3>Your mail could not be sent due to input errors.</h3><hr />';}
        else{echo 
        "<html>
        <body><br><br>
        Order successful, we will be in contact shortly<br>
        </body>
        </html>";
    }
}
?>
<?php
error_reporting(E_ALL);
if (!isset($_POST["submit"])) {
} 

else 
{