Analysis error: syntax error, unexpected $ end of line 1

advertisements

I'm writing a wordpress plugin that integrates with MailChimp's API to store email addresses in a MailChimp list.

I have a 'store-address.php' that run's via AJAX on the submission of a form.

The plugin works when AJAX'ing the url on a local, or GoDaddy WordPress install. But does not work on my staging site wich is hosted on 'MediaTemple.net'.

When I make an ajax call to 'store-address.php' I receive this error...

Parse error: syntax error, unexpected { in /wp-content/plugins/plugin-name/mailchimp-api/inc/store-address.php on line 1

Here is my ajax function

$('#subscribe').submit(function(e) {

        $.ajax({
            url: $plugin_url '/plugin-name/mailchimp-api/inc/store-address.php',
            data: 'ajax=true&email=' + escape($('#email').val()),
            success: function(msg) {
                $('#response').html(msg);
            }
        });

        return false;
    });


And my 'store-address.php' looks like this.

<?php
 if(session_id()==''){
  session_start();
 }
 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');

 /*
  * get MailChimp API details from the plugin settings stored in the session.
  */     $mcKey = $_SESSION['mc_api_key'];
 $mcID = $_SESSION['mc_list_id'];

 $api = new MCAPI($mcKey);
 $list_id = $mcID;

 if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
    return 'Success! Check your email to confirm sign up.';
 }else{
    return 'Error: ' . $api->errorMessage;
 }

}

  /*
   * If being called via ajax, autorun the function
   */
  if($_GET['ajax']){ echo storeAddress(); }
?>

phpVersion 5.5

As I mentioned before this code works on a local environment and a goDaddy hosted site. Just not on MediaTemple I have also swept the code for any PHP syntax errors and I can't find anything.

Any help or point in the right direction would be a godsend. Thanks


The error was caused due to FileZilla's transfer type being set to "Auto", which disrupted linebreaks.

After switching the transfer type to "Binary" and restarting FileZilla, I re-uploaded the plugin and everything works great.

Resource: Filezilla removes line breaks on php files