我有一個腳本可以將我的表單數據發送給分類廣告。昨天當我離開工作時,它工作得很好。現在它只在FireFox中工作,我在Opera和Safari瀏覽器中收到了我的「else」聲明「我們遇到了發送郵件的錯誤,請通知[email protected]」,這對我來說毫無意義。爲什麼這個PHP腳本在firefox中工作正常,但不是Safari或Opera?
什麼原因導致這個錯誤,爲什麼它在某些瀏覽器中失敗,但在其他瀏覽器中工作?
<script language="javascript">
function submitt()
{
setTimeout('document.paypal.submit()',1000);
}
</script>
<?php
$to = "[email protected]" ;
$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 [email protected]"; }
}
}
?>
<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>
是什麼造成這個錯誤,爲什麼它在某些瀏覽器,但其他人的工作失敗?
爲什麼使用花括號,當你有方括號呢? – 2012-08-16 18:13:05
它在某些瀏覽器中不工作*可能與您的輸入和前端代碼有關,而不是PHP。 – 2012-08-16 18:14:50
是的,不要使用數組{}}。正確的用法是'[]'。 – Matt 2012-08-16 18:15:17