ConstantContact Plugin Tutorial

If you use this extra and like it, please consider donating. The suggested donation for this extra is $5.00, but any amount you want to give is fine (really). For a one-time donation of $50.00 you can use all of my non-premium extras with a clear conscience.

ConstantContact is a plugin that adds contacts to an email list at Constant Contact using the Constant Contact API V1.

ConstantContact was developed with the generous support of Fountainhead, LLC dba RS Design.

Installing ConstantContact

Go to System | Package Management on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository. Put ConstantContact in the search box and press Enter. Click on the "Download" button, and once the package is downloaded, click on the "Back to Package Manager" button. That should bring you back to your Package Management grid. Click on the "Install" button next to ConstantContact in the grid. The ConstantContact package should now be installed.


You need a Constant Contact username and password. You do not need an API key. Set the username and password in the ccProperties property set.

At the point in your code where you want to add the contact, create an array of fields for the user and invoke the OnCustomerOrder event.


You want to add a user to your mailing list when he or she completes an eCommerce purchase.

At the point where you confirm the user's purchase, add code like this using the information you have for the user:

$contact = array(
    /* Required */
    'OptInSource' => 'ACTION_BY_CUSTOMER',
    'Status' => 'ACTIVE',
    'ContactList' => 1,
    'Email' => $email,
    'FirstName' => $firstName,
    'LastName' => $lastName,
    /* Optional */
    'City' => $city,
    'CompanyName' => $company,
    'JobTitle' => $title,
    'StateName' => $stateName,
    'StateCode' => $stateCode,
    'CountryCode' => $countryCode,
    'CountryName' => $countryName,
    'Addr1' => $addressOne,
    'Addr2' => $addressTwo,
    'Addr3' => $addressThree,
    'PostalCode' => $postalCode,
    'SubPostalCode' => $postalSubCode,
    'HomePhone' => $homePhone,
    'WorkPhone' => $workPhone,

    $modx->invokeEvent('OnCustomerOrder', array('contact' => $contact));

The plugin checks to make sure there is no user with that email address, then adds the user. Using the class that comes with the package, it's also possible to update or remove existing users, but the plugin itself will only add them.


My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book may still be available from Amazon.

If you have the book and would like to download the code, you can find it here.

If you have the book and would like to see the updates and corrections page, you can find it here.

MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:

  • Installing MODX
  • How MODX Works
  • Working with MODX resources and Elements
  • Using Git with MODX
  • Using common MODX add-on components like SPForm, Login, getResources, and FormIt
  • MODX security Permissions
  • Customizing the MODX Manager
  • Using Form Customization
  • Creating Transport Packages
  • MODX and xPDO object methods
  • MODX System Events
  • Using PHP with MODX

Go here for more information about the book.

Thank you for visiting

  —  Bob Ray