Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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 未在Chrome和Safari中提交表单_Php_Html_Forms_Google Chrome_Safari - Fatal编程技术网

Php 未在Chrome和Safari中提交表单

Php 未在Chrome和Safari中提交表单,php,html,forms,google-chrome,safari,Php,Html,Forms,Google Chrome,Safari,我是PHP新手,所以我不确定代码出了什么问题。我已经在Internet Explorer、FireFox、Chrome和Safari中测试了这个表单,它在IE和FireFox中都非常有效,但在Chrome或Safari中不起作用。在Chrome和Safari中,我都获得了成功提交的页面,但我没有收到发送给我的电子邮件 HTML页面: <form name="balxfrform" action="baltransfer.php" method="POST"> <input

我是PHP新手,所以我不确定代码出了什么问题。我已经在Internet Explorer、FireFox、Chrome和Safari中测试了这个表单,它在IE和FireFox中都非常有效,但在Chrome或Safari中不起作用。在Chrome和Safari中,我都获得了成功提交的页面,但我没有收到发送给我的电子邮件

HTML页面:

 <form name="balxfrform" action="baltransfer.php" method="POST">
 <input type="hidden" name="_SUBJECT" value="Transfer Request Form">

 <b>* Name:</b> <input name="name" type="text" size="60"><br>
 <b>* Email:</b> <input name="email" type="text" size="60"><br>
 <b>Member Number (Last 3 Digits) XXX:</b> <input name="account" type="text" size="10"><br>
 <b>Card Number:</b> <input name="ccnumber" type="text" size="40"><br>
 <b>Phone Number:</b> <input name="pnumber" type="text" size="20"><br>
 <b>Best Time to reach you<sup>1</sup>:</b> <input name="time" type="text" size="40"><br>
 <b>* I agree to the terms and conditions listed below:</b> Yes <input name="terms" type="checkbox" value="Yes"><br>      

  <input type="submit" value="Submit">
  </form>
<?php

if(isset($_POST['email'])) {
    $email_to = "email@test.com";
    $email_subject = "Transfer Request Form";

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

    if(!isset($_POST['name']) ||
       !isset($_POST['email']) ||
       !isset($_POST['account']) ||
       !isset($_POST['ccnumber']) ||
       !isset($_POST['pnumber']) ||
       !isset($_POST['time']) ||
       !isset($_POST['terms'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $account = $_POST['account']; // not required
    $ccnumber = $_POST['ccnumber']; // not required
    $pnumber = $_POST['pnumber']; // not required
    $time = $_POST['time']; // not required
    $terms = $_POST['terms']; // required
    $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,$name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
    }
    if(strlen($error_message) > 0) {
        died($error_message);
    }
    if(!isset($terms)) {
        $error_message .=  'You must agree to the Terms and Conditions to continue.';
    }
    $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($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Member Number XXX: ".clean_string($account)."\n";
    $email_message .= "Card Number: ".clean_string($ccnumber)."\n";
    $email_message .= "Telephone: ".clean_string($pnumber)."\n"; 
    $email_message .= "Best Time to be Reached: ".clean_string($time)."\n"."\n";
    $email_message .= "Agree to Terms and Conditions: ".clean_string($terms)."\n";

    // create email headers
    $headers = 'From: '.$email_from."\r\n".
        'Reply-To: email@test.com'.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
    mail($email_to, $email_subject, $email_message, $headers);  
    ?>

*名称:
*电子邮件:
会员编号(最后3位数字)XXX:
卡号:
电话号码:
联系您的最佳时间1:
*我同意下列条款和条件:是
PHP页面:

 <form name="balxfrform" action="baltransfer.php" method="POST">
 <input type="hidden" name="_SUBJECT" value="Transfer Request Form">

 <b>* Name:</b> <input name="name" type="text" size="60"><br>
 <b>* Email:</b> <input name="email" type="text" size="60"><br>
 <b>Member Number (Last 3 Digits) XXX:</b> <input name="account" type="text" size="10"><br>
 <b>Card Number:</b> <input name="ccnumber" type="text" size="40"><br>
 <b>Phone Number:</b> <input name="pnumber" type="text" size="20"><br>
 <b>Best Time to reach you<sup>1</sup>:</b> <input name="time" type="text" size="40"><br>
 <b>* I agree to the terms and conditions listed below:</b> Yes <input name="terms" type="checkbox" value="Yes"><br>      

  <input type="submit" value="Submit">
  </form>
<?php

if(isset($_POST['email'])) {
    $email_to = "email@test.com";
    $email_subject = "Transfer Request Form";

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

    if(!isset($_POST['name']) ||
       !isset($_POST['email']) ||
       !isset($_POST['account']) ||
       !isset($_POST['ccnumber']) ||
       !isset($_POST['pnumber']) ||
       !isset($_POST['time']) ||
       !isset($_POST['terms'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $account = $_POST['account']; // not required
    $ccnumber = $_POST['ccnumber']; // not required
    $pnumber = $_POST['pnumber']; // not required
    $time = $_POST['time']; // not required
    $terms = $_POST['terms']; // required
    $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,$name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
    }
    if(strlen($error_message) > 0) {
        died($error_message);
    }
    if(!isset($terms)) {
        $error_message .=  'You must agree to the Terms and Conditions to continue.';
    }
    $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($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Member Number XXX: ".clean_string($account)."\n";
    $email_message .= "Card Number: ".clean_string($ccnumber)."\n";
    $email_message .= "Telephone: ".clean_string($pnumber)."\n"; 
    $email_message .= "Best Time to be Reached: ".clean_string($time)."\n"."\n";
    $email_message .= "Agree to Terms and Conditions: ".clean_string($terms)."\n";

    // create email headers
    $headers = 'From: '.$email_from."\r\n".
        'Reply-To: email@test.com'.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
    mail($email_to, $email_subject, $email_message, $headers);  
    ?>

可能与PHP部分无关。PHP在服务器端运行。由于一个浏览器对HTML代码的解释不同,这可能是HTML表单的HTML语法问题。您可以尝试验证您的HTML。试试这个。

试试下面的解决方案 1.)添加@before mail()函数 例如:@mail($email\u to,$email\u subject,$email\u message,$headers)

2.
if(!mail(…)){
//再次调用您的代码

}

您的错误日志中有错误吗?PHP在大多数情况下与浏览器没有任何关系,你知道。@Barmar感谢它的工作。我现在唯一的问题似乎是我问了一个有IE 10的同事来测试表格。他获得了成功完成的页面,但我没有收到电子邮件。你知道为什么会这样吗?再次感谢你的帮助。什么有效?我没有发布答案。检查您的PHP错误日志,看看是否出现了问题。这不是您最初报告的问题吗?如果邮件仍然无法通过,为什么说它有效?检查服务器上的邮件日志,查看邮件是否已发送。可能是目标服务器上的垃圾邮件过滤器阻止了它。