Contact Form on WP site doesn't send emails after 10-12 hours

hi

Quick background, so i have Cloudflare on my website, works great and caches everything.

page rules

https://domain.com/wp-admin
Cache Level: Bypass

https://domain.com/?preview
Cache Level: Bypass

https://domain.com/
Cache Level: Cache Everything, Edge Cache TTL: a month

Want to keep this as-is

I set to “bypass cache” with a cache rule for → /wp-admin/admin-ajax.php

While it does work, it seems to be just temporary, as in after 10-12 hours for some reason, i don’t receive anymore emails from it (nor in the WP admin dashboard) (it shows the green message “Form submitted”). Last night at 22.00 worked, this morning at 08am not working anymore. (nothing changed).

This morning i went to CF dashboard, cleared cache for /wp-admin/admin-ajax.php (just in case), and no change, still no submit.

Then, cleared cache for the entire Contact Page only (not the whole site, still all cached and superfast) → and then form works again - tested 10 times (pc, mobile, etc). So it’s something on the page’s code.

After a few tests, it still works, however i am wondering why after 10-12 hours on cache then it stops working again? Bizarre.

Question

Are there any .php files similar to the ajax i already set to “bypass cache” that i could also bypass?

I rather not choose to bypass cache for the entire contact page, if possible, however if no solutions avail, i will do that.

Cheers,
Gabrio

Caching rule

updated to this, for a test

i’ve removed the recapctha - testing a further 10-12 hours from now. after removal and checking the contact page, it works (with full cache switched on).

hello,

Update:

It’s been 21 hours since clearing cache on CF yesterday. Form perfectly works. So, looks like the REcapctha is the issue here. Good i don’t get much spam (for now) so could stay off.

I was using captcha v2 on Gutena’s settings, i could test v3 as well.

Considering CF Cache bypass for /admin-ajax.php does its job, is there a similar .php or .js file used when REcapctha is on that i could bypass so it does not interfere with the form?

thank you,
Gabrio

hello, me again, I went to the bottom of this and analysed the code entirely.

Just after exactly 24 passed, the form started not working again, hence it’s not the captcha – i thought there must be something that changes after 24 hours but gets blocked because CF doesn’t serve it due to cache.

I dug deeper and,

With a bit of help of ChatGPT, I discovered that the issue is with the “nonce”, which is issued by WordPress and expires after 24 hours. Since i have a cache rule “cache everything for 1 month”, WordPress issues a new nonce after 24 hours, Cloudflare still serves the “expired” one, WordPress isn’t happy and voilà form is stuck and no email.

“nonce”:”e944626262″ this is unique and refreshed every 24 hours.

A simpler approach might be to dynamically load the nonce on the client side via AJAX. This would keep pages cacheable while ensuring that a valid nonce is always used for form submissions. This might involve some changes on the plugin. Frustrations. This contact form looks great.

Workarounds possible are:

  • Entirely disable CF cache for the contact page (not great for international traffic)
  • Change global caching policy to 20 hours (not great also)
  • Change caching policy only on the contact page to 20 hours (this way contact page is still fast and nonce should work)

I just went with option 3, which i think is the best one, everything can remain cached up to 1 month, whereas the contact page will refresh every 20 hours, allowing the new nonce to work.

Back in 24 hours again.

Best Regards,
Gabrio

so hilarious just answering yourself, but in case this helps anybody else:

With CF setting to 8 hours for the contact page it works, problem seems solved.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.