我正在使用我從http://apidocs.mailchimp.com/api/downloads/ 調用的代碼,名爲「MCAPI Simple Subscribe示例代碼」 - 使用jQuery。建立一個MailChimp註冊表單,得到一個PHP解析錯誤神祕
在本地,在PHP版本5.3.5是,它工作得很好。但是,當我將其部署到生產,那裏的PHP版本是5.2.17是,我得到這個錯誤:
Parse error: syntax error, unexpected T_FUNCTION in /home/myperf7/ public_html/inc/store-address.php on line 1
在http://myperfectbicycle.com/看到它在行動 - 你可以看到, 這個錯誤不僅僅是美感。它可以防止表單成功收集 電子郵件地址。
任何想法可能是什麼原因造成的?如果需要,我可以提供進一步的phpinfo()細節 - 只是不想將所有垃圾郵件都發送給您。這裏有商店address.php的內容:
<?php
function storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return "Email address is invalid";
}
require_once('MCAPI.class.php');
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('XXXXXXX');
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "XXXXXXX";
if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
// It worked!
return 'Success! Check your email to confirm sign up.';
}else{
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
if(isset($_GET['ajax'])){ echo storeAddress(); }
?>
什麼分這段代碼不會在PHP 5.2版本正常工作?嗯...
在評論中有人問如何被包括在商店address.php文件;這裏是吧,從我的index.php頁面:
<form id="signup" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" value="" name="email" class="email" id="email" placeholder="email address" required="required" />
<div class="clear">
<input type="submit" value="Notify me" name="subscribe" class="button"/>
</div>
<span id="response"><?php require_once('inc/store-address.php'); if(isset($_GET['submit'])){ echo storeAddress(); } ?></span>
</form>
那麼檢查一下你的PHP 5.3設置是否有相同的錯誤報告配置。您可能會在那裏看到相同的消息。 – hakre
順便說一句,我的託管服務提供商InMotion不會允許我升級到PHP 5.3版本.... :(所以我需要弄清楚如何讓這個代碼以5.2友好的方式工作:) – mark
註釋掉'require_once '。你應該得到一個致命錯誤「Class MCAPI not found」或其他東西。如果是這樣,在'MCAPI.class.php'中可能會出現語法錯誤。不是完整的答案,只是調試的一個步驟。 – adlawson