Error connecting Mailchimp to website

Posted January 03rd, 2023 in Computers
After creating a popup signup form in Mailchimp, you then connect the form to a site which then activates the popup on that site. Sometimes, you may encounter a 406 HTTP status code or sometimes a 404 HTTP status code. Read on to see one way you can fix this, and hopefully it solves your problem or at least helps point you in the right direction.

Create popup form

Firstly, create the popup form in Mailchimp by going to 'Audience' => 'Signup forms' => 'Subscriber pop-up'. Add the fields you would like in the form, and set any style and display options.

Connect site

Once you have created the popup form, you will be asked to enter the URL for your website. Once you enter this, you will be given some code to insert on your webpage. Place this code between the <head></head> section of your webpage as stated, then click the 'Check Connection' button to make sure everything is set up correctly. If clicking the button returns a success, then you are good to go. But, I assume you would not be here reading this if that was the case.



Fixing a 406 HTTP status code when Mailchimp tries to connect

As you can see in the error returned above, a HTTP status code of 406 has been returned. The 406 HTTP status code is describe as: "Not Acceptable client error response code indicates that the server cannot produce a response matching the list of acceptable values" (see here). The most likely reason for this error is that the server has rejected the request from Mailchimp, thus not sending the expected headers as Mailchimp will be looking for a 200 HTTP status code, not a 406 HTTP status code.

If the server rejects the request - look at what kind of firewall might be in place on the website. In this case, the Mod Security firewall was rejecting the 'GuzzleHttp' user agent as it saw that it was a bot. Great for protecting your website, but not so good if you would like to connect Mailchimp!

Disable firewall

To allow Mailchimp to connect to your website, you will need to disable Mod Security in cPanel. If you don't have cPanel, check in whichever control panel is used for your site. It may also not be Mod Security - you may find your hosting provider uses a different firewall. Either way, try disabling the firewall and see if that helps. Note that you may also need to speak to your hosting provider if you do not have access to disable the firewall.

Whitelist Mailchimp IP address

If you disable the firewall and Mailchimp can then connect, you will need to look at whitelisting the Mailchimp IP address/addresses in the Mod Security configuration so that you can re-enable the firewall for your website. This is beyond the scope of this tutorial, but you can find instructions on how to do this on the cPanel website. Note that this is usually not possible through a cPanel account, you would tend to do this through WHM. If you don't have access to WHM, you can ask your hosting provider if they can whitelist the IP in Mod Security.

Troubleshooting a 404 HTTP status code when Mailchimp tries to connect

If a 404 HTTP status code is returned when you try to connect your website, this suggests that the page could not be found - which makes no sense, as you KNOW the page is there, you put the Mailchimp code on it!! Time to dig a little deeper....

If you have access to server logs, you can search to see what errors are showing in the logs when Mailchimp attempts to connect. If you take a look at the following, you will notice that the Mailchimp request has three entries in the logs. The first reflects a 301 HTTP status code, as there was a www redirect in place for this domain. The second entry shows that a 406 HTTP status was called as there is a request to 406.shtml. As the error page 406.shtml does not exist (you can tell because there is a 404 HTTP status), the 404.shtml page was called (which also doesn't exist so that was a 404 HTTP status as well). As the 404 HTTP status was the last to be set, this is what was returned to Mailchimp. Without checking the server logs, you would assume that the issue Mailchimp was having when connecting was due to not being able to find the page - but the original code was a 406 HTTP status code which will direct you to the original solution of disabling the firewall/whitelisting the Mailchimp IP address.



Hopefully this tutorial has assisted you with getting Mailchimp connected. Let us know in the comments if you are still having problems.
 

Comments

No comments

Leave a comment