cancel
Showing results for 
Search instead for 
Did you mean: 

Having issues encoding atom xml email with dynamic data from stored variable in session.

Highlighted
Occasional Participant

Having issues encoding atom xml email with dynamic data from stored variable in session.

I am having some issues with a custom Constant Contact App. I am creating this app to filter contacts in a database based on certain criteria and then creating a new campaign and a new list and adding the contacts included in the query results and also building the html template based on input from the user, ie. date/start time, and end time.

 

This data is all posted from a form and then stored in the Session. I can get everything to work correctly but when I try to add the variables stored in the session to the email template(atom+xml) it errors out with this error(Error 400: The request contains errors in the common Atom sections, which lie outside or , such as , , or .)

 

I assume this is a simple error in the way the email template has to be encoded and I have been searching all over the Constant Contact Developers Resources but cannot understand what I am doing wrong. I will post all of the code I have which is relevant to this main issue below-- Any help would be greatly appreciated:

 

 

<?php
//This is Where I Grab the Posts and store into $_SESSION
$eventdate_session = $_POST['eventdate'];
$eventtimefrom_session = $_POST['eventtimefrom'];
$eventtimeto_session = $_POST['eventtimeto'];

 $_SESSION['eventdate'] = $eventdate_session;
 $_SESSION['eventtimefrom'] =  $eventtimefrom_session;
 $_SESSION['eventtimeto'] = $eventtimeto_session;

?>

<?php
    //Create a new Campaign if a list is created

if (isset($new_id)) {

     //GRAB THE SESSION INFO FOR THE EVENT INFO AND BRING IT INTO THIS CLAUSE
     $eventdate = $_SESSION['eventdate'];
     $eventtimefrom = $_SESSION['eventtimefrom'];
     $eventtimeto = $_SESSION['eventtimeto'];



 // the title for your campaign 

    $title = 'Test Campaign CC API -- DO NOT USE THIS -- ONLY A TEST -- ' .date('d-M-Y'). '';

    // ID's of the contact lists to send the campaign to
    $contact_lists = array($new_id);

    // an associative array of options to send
    // keys are the fieldnames as defined by constant contact
    $options = array(

        // email address you send the email from, has to be registered and active for this to work
        'EmailAddress' => 'info@demo.com', 

        // name associated with the email address your send from , can be anything you like
        'FromName' => 'API TEST',

        // subject for the new email
        'Subject' => 'API -- Tester Email' .date('d-M-Y'),

        // see the constant contact link above for a description of these fields.
        'ViewAsWebpage' => 'NO',
        'ViewAsWebpageLinkText' => 'NO',
        'ViewAsWebpageText' => 'NO',
        'PermissionReminder' => 'YES',
        'PermissionReminderText' => 'You\'re receiving this email because of your relationship with ctct. 
Please &lt;ConfirmOptin>&lt;a style="color:#0000ff;">confirm&lt;/a>&lt;/ConfirmOptin> 
your continued interest in receiving email from us.',
        'GreetingSalutation' => 'Dear',
        'GreetingName' => 'FirstName',
        'GreetingString' => 'Greetings!',
        'OrganizationName' => 'ctct',
        'OrganizationAddress1' => '123 wsw st',
        'OrganizationAddress2' => 'NO',
        'OrganizationAddress3' => 'NO',
        'OrganizationCity' => 'Ashland',
        'OrganizationState' => 'MA',
        'OrganizationInternationalState' => '',
        'OrganizationCountry' => 'us',
        'OrganizationPostalCode' => '32423',
        'IncludeForwardEmail' => 'NO',
        'ForwardEmailLinkText' => '',
        'IncludeSubscribeLink' => 'NO',
        'SubscribeLinkText' => '',
        'EmailContentFormat' => 'HTML',
        'EmailContent' => '&lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" 
xmlns:cctd="http://www.constantcontact.com/cctd">
&lt;body>&lt;CopyRight> <br><br> This is just a test to see if this will work!!!!!!! <br><br>Next is some HTML <a href="http://www.google.com" border="0">Goto Google.com</a>'.htmlentities($eventdate).'<br>' .htmlentities($eventtimefrom). '<br>' .htmlentities($eventtimeto).'Copyright (c) 1996-2009 Constant Contact. All rights reserved.  Except as permitted under a
separate
written agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on any
Constant Contact site,
including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, or
distributed without the
prior written permission of Constant Contact.  For inquiries regarding reproduction or distribution of any Constant
Contact material, please
contact joesflowers@example.com.&lt;/CopyRight>
&lt;OpenTracking/>
&lt;!--  Do NOT delete previous line if you want to get statistics on the number of opened emails -->
&lt;CustomBlock name="letter.intro" title="Personalization">
    &lt;Greeting/>
&lt;/CustomBlock>

&lt;/body>
&lt;/html>',
        'EmailTextContent' => '&lt;Text>&lt;/Text>',
        'StyleSheet' => '',
    );





    // call the create_campaign() method
    $campaign_id = $cc->create_campaign($title, $contact_lists, $options);

    if($campaign_id):
        echo "<p>A new campaign has been created with ID: '$campaign_id'</p>";
    else:
        // if an error occurs we can debug it any various ways

        // show a simple error to the user
        echo "Campaign could not be created " . $cc->http_get_response_code_error($cc->http_response_code);

        // or output the last http request and response strings, for debugging only
        $cc->show_last_connection();

        // usually the http_response_body will contain a more descriptive error to help debug
        if($cc->http_response_body):
            echo '<p>' . $cc->http_response_body . '</p>';
        endif;
    endif;

 } // Ending the if not empty clause for the new campaign creation if a list is created...


?>

 

Does anyone have any ideas why this might be causing errors and not creating the new campaign? When I delete the variables from the email template the campaign will create correctly so I assume that those are the issue here.

The detailed debugging message is below:

 

 

Campaign could not be created Invalid Request - There are many possible causes for this error, but most commonly there is a problem with the structure or content of XML your application provided. Carefully review your XML. One simple test approach is to perform a GET on a URI and use the GET response as an input to a PUT for the same resource. With minor modifications, the input can be used for a POST as well.POST /ws/customers/{user}/campaigns HTTP/1.1 Host: api.constantcontact.com Content-Type: application/atom+xml User-Agent: justphp 2.0 Content-Length: 4689 Authorization: Basic

 

Thanks in advance,

 

Mike

Tags (3)
9 REPLIES 9
CTCT Employee

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hello,

 

I took a look at your code and I believe I see a one problem that may resolve the problem.  However, are you using one of our wrappers?  Where are you getting the "create_campaign" function from?  I do not believe any of our wrappers current version have a function named "create_campaign", if you could send me the file you are using that calls that function, I should be able to run the code and help a lot further.

 

The main issue I see with the current code is that the new code you put in email content is not being HTML encoded.  When sending HTML through our XML you must HTML encoded every tag.

 

Let me know if you have any questions.

Benjamin Soder
NOC Analyst
Constant Contact
Occasional Participant

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hello Benjamin,

 

Thanks for the quick reply.  I am using a third party php wrapper I will attach the file so you can take a look.  The code works as long as I dont have any variables in the email template like I am doing.  I am pulling variables stored in a $_SESSION.

 

I've uploaded the file here as I didn't see an attach file in your WYSIWYG editor:

 

Im pretty sure it has something to do with the way I am including the variables into the email template options array.

 

I appreciate your help!

 

Mike

CTCT Employee

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hi Mike,

 

I'm taking a look now at the code and the library, and I will post back here when I figure out what is going on.

Benjamin Soder
NOC Analyst
Constant Contact
Occasional Participant

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Thanks Benjamin, I appreciate you looking into it for me. 

Occasional Participant

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Ben,

 

Any luck finding out what might be happening with the dynamic email?  If it'd be easier I can send you the exact files I am using I just didn't want to post them openly on the forums.  Let me know what you think.

 

Thanks Again,

 

Mike

CTCT Employee

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hello,

 

That would probably be the easiest way to do this.  Please send them here, and I will look at them now!

 

Thanks,

Benjamin Soder
NOC Analyst
Constant Contact
Occasional Participant

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Thanks Ben,

 

I just sent the email over, the first i forgot the attachedment but I sent another with it.

 

Mike

Occasional Participant

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hey Ben,

 

After checking out the files I sent over have you noticed what might be happening with adding the variables from the _SESSION data into the html email template array?

 

Let me know if you can help me out with this I would be very happy to get this working for my company.

 

Thanks,

 

Mike

CTCT Employee

Re: Having issues encoding atom xml email with dynamic data from stored variable in session.

Hello,

 

I apologize for the delay, I have just sent you a response through email.

 

Ben

Benjamin Soder
NOC Analyst
Constant Contact