mailchimp_modx2In this post we’re going to go over how to get the MailChimp snippet set up and working on your MODx Evolution site.  MailChimp is a service that allows you to send email newsletters, manage subscriber lists, and track campaign performance.  You can of course simply create the forms and such directly in MailChimp and paste the supplied code into your site, but this little snippet works just great.  The directions I will outline here are also covered in the documentation inside the snippet folder, but I thought I would go over it for my own future reference and for anyone who may not be aware that this snippet exists or who may have had trouble setting it up.  I am using MODx Evolution 1.0.2 and will be setting this demo up on the Learn MODx website.

MailChimp

You need a MailChimp account and at least one list to work through this tutorial. Setting up an account on MailChimp is free, and you can opt for the free plan to start out and then upgrade to the paid plan as your needs increase.  We’re going to create a demo list for the coding pad for this tutorial.

mailchimp_modx1

Get the MODx MailChimp Snippet

The snippet to make this work was created and generously shared by MODx developer Garry Nutting and is available on the MODx forum.  I am also attaching the snippet to this post for ease of download. But make sure you visit the thread for support and more comments.

Download the MODx MailChimp snippet

Install the Snippet

As always, the process of installing the snippet is pretty straightforward.

  1. Extract the files to your desktop or other convenient location.
  2. Inside the zipped file you will find the folder named ‘mailchimp‘, inside of which are two folders – ‘classes‘ and ‘includes‘ as well as several files. Upload this mailchimp folder to your assets->snippets folder.
  3. Next, in your site manager, under Elements->Manage Elements->Snippets, create a new snippet and call it mailchimpSubscribe.  In the code block, paste the code found in the subscribe.snippet.php file.

Configuring the snippet

So now we have the snippet installed and ready to go, but you need to do one more thing to make sure that it can access your account and get information about your specific lists. To do this, you need to edit the file config.inc.php that’s inside the includes folder.  Here, you need to place your MailChimp account user name and password. Simply replace <USERNAME> with your username and <PASSWORD> with your password.  You can do this before uploading the files, or afterward in the manager.

Create the Form

Next, you have to create a chunk with the actual form that users will fill out to subscribe to your list.  Again the process is pretty straightforward.  When you create a list in MailChimp, you decide how many fields the form should have. It can be a simple form with just an email address, or one that has more fields, such as first name, last name, and email.  The default fields when you create a form are currently first name, last name, and email address.  Adding more fields is easy, go to your list, and click “Settings”

mailchimp_modx3

Click on “List Fields and *|MERGE|* Tags“.  Here, you can add new fields that your user will fill when subscribing to your list.  For our demo list, we’re going to add a field for the subscriber to add their website url.  You can also delete the first and/or last name fields here if you don’t want them to appear. The only field that must be present is the email field.

Make sure also that you note the tag names for the fields (highlighted below in green) as we will need these to create the form chunk.

mailchimp_modx4

To create the form, create a new chunk and call it whatever you want. I will call mine mcSubscribeForm.  In this chunk, we simple enter the usual HTML for a form, with MODx variables, and our field tag names from MailChimp. Note that the field names have the prefix mc_ and then the tag name.


<p>[+MailChimp.message+]</p>
<form method="post" action="[~[*id*]~]">
 <label>First Name: <input type="text" name="mc_FNAME" value="" /></label><br />
 <label>Last Name: <input type="text" name="mc_LNAME" value="" /></label><br />
 <label>Email: <input type="text" name="mc_EMAIL" value="" /></label><br />
 <label>Website: <input type="text" name="mc_URL" value="" /></label><br />
 <input type="submit" name="subscribe" value="Subscribe" />
</form>

You can add more labels and inputs depending on your fields or remove the ones you don’t need.  To add another field that you had created for your list form you would use the same syntax as above:

<label>LABEL : <input type=”text” name=”mc_TAG” value=”” /></label><br />

The Subscribe button MUST retain the name “subscribe”, so leave that unchanged.  Once this is done, your snippet is more or less ready to go.

You can also add checkbox or dropdown type of fields but I honestly haven’t tried it, but I’m sure it’s doable.  For now we’re going to keep this simple.

Calling the Snippet

The last thing we need to do before calling our snippet and setting things up is to find our listID.  You can find this in MailChimp by going to lists and again by selecting “Settings” as before. Scroll down the page and you’ll find the list ID.  Copy this somewhere, you will need to insert it into your snippet call.

mailchimp_modx5

So now you’re ready to go.  The snippet call is pretty straightforward.  The two parameters are &form, which is the name of your form chunk, and &listId, which is the list ID for your list.

[!mailchimpSubscribe? &form=`your_form_chunkname` &listId=`your_listID` !]

In my case, the snippet call with my form chunk name and my list ID would be:

[!mailchimpSubscribe? &form=`mcSubscribeForm` &listId=`9627f9b5a4` !]

If you’ve done everything right, you should now get a form on your site where your users can subscribe themselves to your list and you can send them newsletters and campaigns.

mailchimp_modx6

You can ofcourse style the form to your heart’s content by adding the appropriate CSS to your style files.

This snippet is nice and works well in allowing a more seamless integration of MailChimp within your MODx website.  It doesn’t have a lot of parameters but it does the trick.  Test it and let me know how you like it. Also, don’t forget to visit the forum thread and drop a thank you to Garry for creating this and making it available for us to use.

More Reading and Resources
Download the MODx MailChimp snippet
MODx forum thread
MailChimp Knowledgebase

About The Author

43 Comments

  1. Hi Mary, great blog post 🙂 The post explains the setup perfectly and will make it super-easy for MailChimpers everywhere to get it working with MODx. Keep up the good work!

    (And, thanks for the mention!)

  2. This is what I want for my independent candidate for president web site. name ‘ mail / website with only name required.

    Then, after the visitor comments, the comment is posted. I want to put this on every page. I have modX uploaded in a file. I have b2evolution uploaded and word press, too.

    Originally I wanted to use Modx but the person who uploaded it for me said I should use word press. I don’t like word press.

    Could someone give me a hand?

    Michael Stephen Levinson

    • Mike
      Do you have MODx already installed? If you go through the beginner tutorials (see link at the top), they will walk you through the process of installing MODx, adding your template and content, and then adding the ability for others to comment. WordPress is great if you’re building a blog.

      I recommend that you set everything up on a separate folder or subdomain first so that it doesn’t mess up your existing website and then once you have it working you can transfer it over to your main domain name.

      If you want someone to build the website for you I can do it at a fee – just use my contact form to send me more details.

      Hope this helps
      mary

  3. Another super excellent tutorial!! This will be very useful to many people.

    MODx and all its devotees are lucky to have a supporter like you 😀

  4. Hi Mary Hi Wendy Hi Gary,

    I’m a poet, not a programmer. By way of an introduction, here is a little poem:

    Night watch on the ship’s prow,
    The stars are out in disorder,
    Every thing ever been seen,
    By the naked eye / Is out tonight.

    The key to the poem is the word(s) “every thing.”
    Every star, comet, planet, reflecting asteroid, cosmic particle . . . every thing – everything what? Everything ever been seen? Been seen how? Been seen by the naked eye (pause) is out tonight.

    The world’s whole long term history (before Hubble) is brought to the bow of a ship in the wilderness of the open sea . . . dazzling . . . every thing ever been seen , By the naked eye / Is out tonight.

    I like the newfangled way of dividing the last line of the verse with a computer geek forward slash for a pause.

    Mine is a giant sense of words, world orders and word hors d’oeuvres, a new word order; but I don’t do computer code beyond some html. I liked html when I first saw it because my name is michael levinson . . ml.

    I recently published “New World Hors D’oeuvres” (sub-titled) The Recipe for World Peace. Here is a pdf of the 224 page book:
    {link removed} and here is {link removed} where you can see and hear the opening column in my Television Scripture that begins with Adman and Even in the Gar Den ov Edum.

    (What an introduction!)

    I have modx on the michaelslevinson.com web server . I host with Hostmonster. I like them. The “C panel” has a link to ‘simple scripts, so the installation was a couple mouse clicks. But from there I am in trouble.

    I could probably, by trial and error, maybe insert code for a link to the modx folder but what i want is that simple beautiful modx blog -leave a comment window to show up at the bottom of my home page (the index.html page) and maybe above the window “post a comment and the poet will post back.” Maybe i will add a line about how I want to campaign for president – online one on one via the blog window – not flying around on airplanes and doing rope lines as that is just wasteful and useless.

    I am not going to be able to figure out how to do this by myself so I need to convince one of you guys to either go on my site and do it, or send me the simple steps with the code.

    I am very tight for money currently living on $800 a month out of which comes rent, utilities, food, gas, car insurance. But my web site is getting thousands of hits a month!

    I am also getting ready to file big time complaint against all the TV networks with FCC and I am asking for 21 million dollars in damages – that besides another filing in Federal District Court against the networks and FCC which will jump under the law from the district court to the Supreme court. Suffice to say I have a lot on my plate.

    I could put up a spiffy ad for your services. I don’t need to build a web site (though mine could be improved) but I do need some of your expertise. I suspect i am talking about less than an hour of actual work because this is all 2nd nature to you programmers, but I am not NOT disrespecting the value of your knowledge.

    Look at “New World Hors D’oeuvres because I could come up with a signed 1st edition. That is all for the moment.

    In good faith

    Michael S. Levinson

    • Michael
      This is just my personal blog. I recommend that if you need free help you post on the MODx support forums and if you are patient people will walk you through the process of what you need to accomplish. I also advise that you post on websites like getafreelancer.com where there is a wide range of providers who offer a wide range of services for relatively low rates. I think you will have a good chance of success there.

      Best wishes
      mary

  5. I have used Omnistar Mailer http://www.omnistarmailer.com for 3 years now and I like it.

  6. Hi Mary. I am stuck at editing the config file.
    I went to manger>includes in Modx and opened the file but
    I am not finding the lines .
    do you mean these lines?
    $database_user = ‘myname’;
    $database_password = ‘mypassword’;
    or should I be looking in Mailchimp?

    thank you,
    I’m sure I’m missing something simple-just not sure what it is.

  7. Update: I was able to do everything else in the tutorial easily. I’m just stuck on the config file part. The file only seems to refer to Modx sessions, so I don’t know what to change. Any chance I could get a screenshot?

    • Lisa
      The includes folder you should be looking at is the one inside the mailchimp snippet folder, NOT the one inside the MODx manager folder.

      So you’re looking at assets->snippets->mailchimp->includes

      Hope this helps. Sorry for the confusion.

      mary

  8. Oh… now I get it.
    The config file in the mailchimp snippet folder.
    It’s working great. Thanks so much for answering my question.

  9. Hi Mary. When i test the sign up form sign in i see the error message “Login to remote service failed”.
    I checked the mailchimpSubscribe snippet and the password and username are correct. any suggestions about where to start debugging?

  10. Hi Mary

    Thanks for the excellent tutorial. I’m having fun with MailChimp!

    Hope the move goes well.

    Best

  11. Hi
    I set up an account now with mailchimp and now i’m on the process of sending a test newsletter. I think so far it works, now the problem is i want to send it but the “Send” button is grayed out?
    I thought the price plan is free for subsribers 0-500? Why i can’t send it then?

    Best

  12. Anyone know if anything has changed recently? I had everything working and now instead I get an error:

    fsockopen() [function.fsockopen]: unable to connect to api.mailchimp.com:8 (Connection timed out)

    I have the correct username, password and list id setup, but this has me stumped.

  13. Will these instructions work for integrating with MODx Revo 2.0.7+??

    Aside from the different notations for snippets and chunks and whatnot…

    Thank you, Tom

  14. is there anyone here tried to use this snippets on REVO?
    Thanks

  15. I have a question, i istalled the script but i get “There was a problem subscribing you.”

    Can anyone help me? or have any clue?

    • Anton
      Sometimes the mailchimp service goes down. I sometimes get that error. If you’re getting it repeatedly can you post and tell me your environment settings, what version of MODX, etc.

      mary

  16. I get the message:
    Login to remote service failed

    I can’t find MailChimps field:
    Stick this tag in your content

    Does the remote service error got anything to do with the fields or because of some MailChimp update?

  17. I guess this old way doesn’t work anymore, I have tried the new way by using the API. Still no success atm. (revo update)

  18. Thanks Mary, I will test that 😀

  19. I need them for Evo, these 2 links are for Revo 🙁

  20. Just noticed your `learn modx` site also has the: `Login to remote service failed` message.

  21. Anyone knows if this still works with modx evolution 1.0.6 and above?I too get the “Login to remote service failed” message on your test website Mary (learn modx).
    Maybe mailchimp’s api has changed?

    • Kostas
      Thanks for your comment. I do think the mailchimp API has changed since I wrote that tutorial. I will have a look when I get a chance and post an update if necessary.

      cheers
      mary

      • Thank you for your quick reply Mary. The link inside the config file “http://api.mailchimp.com/1.1/”
        gave me this hint, since it couldn’t still be version 1.1 after that long 😀 .

        Looking forward to the changes 🙂

  22. So just to confirm this snippet no longer works?

    I am getting the same ‘Login to remote service failed’ message using Evo 1.10.

    I also wondered if special characters in your password might throw this off?

    • Eliot
      I need to look into this. I think MailChimp may have changed their API and how you access it. I have switched to using Aweber for most of my needs so I will need to revisit this again and take a closer look. I’ll post an update (and send you an email) when I have some answers.

      mary

Leave a Reply to mary Cancel reply

Close