I'm working with the code I got from http://apidocs.mailchimp.com/api/downloads/ called "MCAPI Simple Subscribe Example code" -- the one with jQuery.
Locally, where the PHP version is 5.3.5, it works just fine. But when I deploy it to production, where the PHP version is which is 5.2.17, I get this error:
Parse error: syntax error, unexpected T_FUNCTION in /home/myperf7/ public_html/inc/store-address.php on line 1
See it in action at http://myperfectbicycle.com/ -- as you can see, this error is not just aesthetic. It prevents the form from collecting the email address successfully.
Any idea what might be causing that? I can provide further phpinfo() details if needed -- just don't want to spam you all. Here are the contents of store-address.php:
<?php
function storeAdd开发者_JAVA技巧ress(){
// 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(); }
?>
What portion of this code wouldn't work properly in PHP version 5.2? Hmmm...
In the comments somebody asked how the store-address.php file being included; here is it, from my index.php page:
<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>
Given that the error is on line 1, and looking on your site is says:
Parse error: syntax error, unexpected T_STRING in /home/myperf7/public_html/inc/store-address.php on line 1
I would suggest opening up your store-address.php and looking for any random strings, spaces, newlines, etc. on the first line of the file. Also, it might be a good idea to have the storeAddress()
response block on multiple lines.
<span id="response"><?php
require_once('inc/store-address.php');
if(isset($_GET['submit'])){
echo storeAddress();
}
?></span>
The require_once()
certainly should be on a separate line.
精彩评论