We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Byte order mark appearing

MarcFreeman
Regular Participant

Byte order mark appearing

Hi there,


Im trying to create a form that adds a user to constant contact in PHP. I have posted the data so that the page reloads itself and it then is supposed to add the post data to constant contact but when the page reloads I get these weird symbols appear at the top of the page .


Ive googled around and apparently its the Byte Order Mark? Ive tried uploading the class file and the page using binary format but i dont get any luck.


Ive tried trouble shooting it myself and i find that it prints out this weird symbols on the doServerCall() method right after $emessage = curl_exec($ch);


here is my code


       include_once('../library/cc_class.class.php');

       $ccContactOBJ = new CC_Contact();

       $postFields = array();

       $postFields = $_POST;

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '1';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        // The Code is looking for a State Code For Example TX instead of Texas

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields = '.';

        $postFields= '.';

         $postFields = '1';

         $postFields = '.';

         $postFields = 'Do Not Mail';

         $contactXML = $ccContactOBJ->createContactXML(null,$postFields);

         $ccContactOBJ->addSubscriber($contactXML);

8 REPLIES 8
David_J
Employee

While I cannot say for sure that this is the issue, the character that you are seeing could mean you are using a text editor that is saving files in UTF-8 encoding with the Byte Order Mark (BOM). Without knowing which text editor you are using it is impossible for me to say, but if you’d like to let me know which program you are using I would be happy to do some testing on my end and see if I am able to replicate.

David J

MarcFreeman
Regular Participant

Hi david,


thanks for your quick reply, im using Netbeans 6.8


Saved alot of files with this before and never had a problem.

David_J
Employee

I have done some more research into this, and while NetBeans does save all files with UTF-8 encoding by default, none of the files I checked had a byte order mark inserted into them, at least with the Windows Version.


 


Just for your information - the byte order mark test I am using is at http://people.w3.org/rishida/utils/bomtester/index.php.


 


After some more testing, it appears that some of the pages in our current PHP Sample forms were saved by a program that DOES insert a bom at the begining of the files, which means that cc_class.php begins with a bom. I am going to be repackaging the PHP sample later today and will reply once I have completed that. In the mean time, if you open cc_class.php in NetBeans you should be able to see this byte order mark, remove it, resave the file, and upload it to your server.


 


Please let us know if this resolves the issue you're running into. Thank you.

David J

David_J
Employee

I had adjusted both the PHP Sample Signup Form, as well as the PHP Campaign Sample, and you can download both of these on our Sample Codes page. I hope that this resolves the issue that you were experiencing. Please let me know if that fixes it, and feel free to reply with any other questions or concerns that you have regarding this. Thank you.

David J

MarcFreeman
Regular Participant

thanks david, that seems to have removed the bom. However im havin another issue.


Keep getting a 'The requested URL returned error: 400' which im guessing is because of malformed xml?


Could you provide me with an example xml of adding an email to constant contact to see what the error is?

David_J
Employee

The minimum XML required to add a contact is located at Creating a Contact. If you are getting a 400 error and would like to post your XML, I would be happy to take a look and see if I can assist in figuring out what modifications need to be made?

David J

MarcFreeman
Regular Participant

Managed to get it to work. If anyones interested my xml was not outputting the correct list id. I thought it was just a number but it needs the whole url.


Also assign the list to $postFields instead of just $postFields


thanks so much for the support david

David_J
Employee

Just to make sure this is clear - the createContactXML function that you are passing your $postFields array to, is expecting $postFields to be an array itself. So you could use....


 


$contactLists = array();


$contactLists = "https://api.constantcontact.com/ws/customers/{user-name}/lists/1";


$contactLists = https://api.constantcontact.com/ws/customers/{user-name}/lists/2";


$postFields = array();


$postFields = $contactLists;


 


You would of course need to include the rest of the information such as first name, last name, email address etc in the $postFields array, but this would add a contact to list 1 and 2 if that is what you are looking to do.

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page