为什么在Firefox这个PHP脚本的工作很好,但不是Safari浏览器或Opera?(Why do

2019-09-28 17:51发布

我有我的邮件我的表单数据,一个分类广告的脚本。 昨天,当我离开工作,它工作得很好。 现在,它只是在Firefox的工作,我让我的“其他人”的声明:“我们遇到了一个错误发送您的邮件,请立即通知XXXX@XX.COM”在这两个Opera和Safari这是没有意义的我。

是什么造成这个错误,为什么它在某些浏览器失败,但在其他工作吗?

 <script language="javascript">
function submitt()
{
setTimeout('document.paypal.submit()',1000);
}
</script>

<?php 
 $to = "XXX@XXX.com" ; 
 $from = $_REQUEST['email'] ; 
 $name = $_REQUEST['Name'] ; 
 $headers = "From: $from"; 
 $subject = "Classified Tests"; 

 $fields = array(); 
 $fields{"Name"} = "Name";  
 $fields{"email"} = "Email"; 
 $fields{"Phone"} = "Phone"; 
 $fields{"Address"} = "Street Address";
 $fields{"City"} = "City";  
 $fields{"State"} = "State"; 
 $fields{"Zip"} = "Zip Code"; 
 $fields{"Classification"} = "Classification"; 
 $fields{"Ad-Headline"} = "Headline"; 
 $fields{"Ad-Content"} = "Ad Content"; 
 $fields{"Words"} = "Word Count"; 
 $fields{"Weeks"} = "Weeks to Run"; 
 $fields{"WordCount"} = "Total Words"; 
 $fields{"Rate"} = "Word Rate"; 
 $fields{"GrossAmountDue"} = "Gross Amount"; 
 $fields{"NonProfit"} = "Non Profit Ad?"; 

$item_name   = $_POST['item_name'];
$amount   = $_POST['amount'] ; 
$currency_code  = $_POST['currency_code'];
$no_shipping = $_POST['item_number'];
$shipping = $_POST['item_number'];
$cmd   = $_POST['cmd'];
$bn  = $_POST['bn'];
$no_note = $_POST['item_number'];
$lc   = $_POST['lc'];
$business   = $_POST['business'];

 $body = "This Ad has been submitted:\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

 if($from == '') {print "You have not entered an email, please go back and try again";} 
 else { 
 if($name == '') {print "You have not entered a name, please go back and try again";} 
 else { 
 $send = mail($to, $subject, $body, $headers); 
 if($send) 
 {print "Your Ad has been submitted, redirecting to paypal."; echo "<SCRIPT LANGUAGE='javascript'>submitt();</SCRIPT>";} 
 else 
 {print "We encountered an error sending your mail, please notify XXX@XXX.com"; } 
 }
}


 ?> 

<form action="https://www.paypal.com/cgi-bin/webscr" id="paypal" target="_self" name="paypal" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="XXXXXXXXXXXX">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Classified Ad">
<input type="hidden" name="amount" id="Amount" value="">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
</form>

是什么造成这个错误,为什么它在某些浏览器失败,但在其他工作吗?

Answer 1:

如果您从您自己的电子邮件地址与发送它会工作PHP_EOL

mail("XXX@XXX.com", "subject", "body", "From: Me" . PHP_EOL); // 'From' can be anything

见PHP: mail -手动 。



Answer 2:

尝试在意见建议,然后再尝试使用此JavaScript代码:

<script type="text/javascript">
function submit()
{
setTimeout(function(){document.paypal.submit();},1000);
}
</script>

我包裹在一个匿名函数的代码提交,而不是一个字符串,在这里鼓励: 高效的JavaScript - Dev.Opera 。

此外,使用<script language=过时 ,应使用type ,而不是( text/javascript )。 见script - MDN 。



文章来源: Why does this php script work fine in firefox but not Safari or Opera?