Confirmation mail is sent every time user_save() is called for users with pending status

Created on 27 November 2018, almost 7 years ago
Updated 10 July 2025, about 2 months ago

(This is a similar issue as #2706593: Opt-in confirmation mail is sent every time user_save() is called for users with pending status , but for D8.)

I have a MailChimp subscription field configured on the user entity, and configured the field to be double opt-in. In a custom module, I am adding a role to every new user in hook_user_insert(), including calling $user->save(). This results in the user receiving two Mailchimp opt-in emails: one that's triggered by the initial creation of the new user account, and one that's triggered by the call to $user->save() in custom code.

Attached patch does the following:

- Adds a 'Prevent multiple subscriptions' setting to the subscribe field.
- If that setting is enabled, \Drupal\mailchimp_lists\Plugin\Field\FieldType\MailchimpListsSubscription::preSave will check the Mailchimp member info for the user's email address. If the Mailchimp member has a 'pending' status (i.e., if Mailchimp is waiting for a confirmation from the user), the user won't be subscribed a second time, and won't get a second (or third, fourth, ...) opt-in email.

I'm not sure if this is the best/cleanest/... way to solve this, feedback welcome :)

🐛 Bug report
Status

Closed: won't fix

Version

1.0

Component

Lists Module

Created by

🇨🇦Canada brunodbo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States xenophyle

    Thanks for submitting this ticket — and sorry we didn’t get back to you about it sooner. We are cleaning up old issues and issue for old versions and are going to close this one. If this issue is still relevant for you, please re-open it and update the “Version” field, and include any updates to the behavior you are seeing.With a smaller issue queue, we’ll have an easier time getting back to you.

Production build 0.71.5 2024