Magento2: Customer incorrectly receives Newsletter Unsubscribe email when account confirmation is enabled and they check "Subscribe to newsletter"

Created on 29 May 2020  ·  20Comments  ·  Source: magento/magento2

Preconditions (*)

  1. Magento 2.3.4
  2. "Require Emails Confirmation" configuration option set to "Yes"

Steps to reproduce (*)

  1. Go to register account page
  2. Fill in details
  3. Check "Subscribe to newsletter"

Expected result (*)

  1. Customer should receive "Please confirm your account" and "Newsletter Subscribe Success" emails

Actual result (*)

  1. Customer receives "Please confirm your account" and "Newsletter Unsubscribe Success" email

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [ ] Severity: S0 _- Affects critical data or functionality and leaves users without workaround._
  • [ ] Severity: S1 _- Affects critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S2 _- Affects non-critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S3 _- Affects non-critical data or functionality and does not force users to employ a workaround._
  • [ ] Severity: S4 _- Affects aesthetics, professional look and feel, “quality” or “usability”._
needs update

Most helpful comment

I have experienced this issue also in 2.3.5p1. The store is configured to require customer email confirmation. If a customer chooses to subscribe to the newsletter during registration, they receive the "Newsletter unsubscription success" email at the same time they receive the confirmation email and end up unsubscribed even after they confirm their email.

I looked into it and I believe the problem is in the Magento\Newsletter\Model\Subscriber class, specifically in the _updateCustomerSubscription function.

Around line 604 there are some if/else conditionals that are evaluated if the _updateCustomerSubscription function is run without the $subscribe parameter set.

There are currently three possible outcomes:

  1. The customer newsletter status is STATUS_UNCONFIRMED and the customer has confirmed their registration. In this case, the customer newsletter status is set to be STATUS_SUBSCRIBED.
  2. The customer newsletter status is STATUS_NOT_ACTIVE and the customer has confirmed their registration. In this case, the newsletter status remains as STATUS_NOT_ACTIVE.
  3. If neither of the two above conditions applies, the customer newsletter status is set to STATUS_UNSUBSCRIBED.

I believe there should be an additional elseif condition that checks to see if the newsletter status is STATUS_UNCONFIRMED and the customer has also not confirmed their registration, and if so - it should leave their status as STATUS_UNCONFIRMED. Without this additional check, an unconfirmed customer with unconfirmed newsletter status falls into the last else statement and is set to STATUS_UNSUBSCRIBED.

The solution would look something like this:

        } elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
            $status = self::STATUS_SUBSCRIBED;
            $sendInformationEmail = true;
        } elseif (($this->getStatus() == self::STATUS_NOT_ACTIVE) && ($customerData->getConfirmation() === null)) {
            $status = self::STATUS_NOT_ACTIVE;
        } elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() !== null)) {
            // If the newsletter status is unconfirmed and our customer is unconfirmed, leave them unconfirmed
            $status = self::STATUS_UNCONFIRMED;
        } else {
            $status = self::STATUS_UNSUBSCRIBED;
        }

In testing, this modification caused the process to behave as expected. When the customer registered and chose to subscribe to the newsletter they would first receive the confirmation email, and upon successful confirmation they would then receive the "Newsletter Subscription Success" email, as expected.

All 20 comments

Hi @paul-gene. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


https://github.com/magento/magento2/pull/23737 was supposed to fix an issue with multiple emails, but has apparently introduced the issue above.

I have tested on 2.3.3 and everything works as it should.

@magento give me 2.4-develop instance

Hi @ajithkumar-maragathavel. Thank you for your request. I'm working on Magento 2.4-develop instance for you

Hi @ajithkumar-maragathavel, here is your Magento instance.
Admin access: https://i-28419-2-4-develop.instances.magento-community.engineering/admin_8d8a
Login: 0116bbb5 Password: b20e2239b32e
Instance will be terminated in up to 3 hours.

@ajithkumar-maragathavel you have requested a 2.4 instance, but this is on 2.3.4, and I am not in a position to use 2.4.

@paul-gene I applied the revert.txt in my magento 2.3.4 and it works, but when a client creates his account he enters it without needing to confirm it, in my store I have activated the account confirmation and the confirmation email if it arrives, but when creating the account the clients access directly to your profile without confirming it

As I already mentioned in https://github.com/magento/magento2/issues/23729, I can reproduce it in 2.3.5 and 2.3.5p1

apparently this persists in magento 2.3.5 as well as magento 2.3.4

@magento give me 2.4-develop instance

Hi @Stepa4man. Thank you for your request. I'm working on Magento 2.4-develop instance for you

Hi, please be aware that receiving the email is not the major issue here, but the subscriber's status is unsubscribed regardless the chosen option in the registration form!

I have experienced this issue also in 2.3.5p1. The store is configured to require customer email confirmation. If a customer chooses to subscribe to the newsletter during registration, they receive the "Newsletter unsubscription success" email at the same time they receive the confirmation email and end up unsubscribed even after they confirm their email.

I looked into it and I believe the problem is in the Magento\Newsletter\Model\Subscriber class, specifically in the _updateCustomerSubscription function.

Around line 604 there are some if/else conditionals that are evaluated if the _updateCustomerSubscription function is run without the $subscribe parameter set.

There are currently three possible outcomes:

  1. The customer newsletter status is STATUS_UNCONFIRMED and the customer has confirmed their registration. In this case, the customer newsletter status is set to be STATUS_SUBSCRIBED.
  2. The customer newsletter status is STATUS_NOT_ACTIVE and the customer has confirmed their registration. In this case, the newsletter status remains as STATUS_NOT_ACTIVE.
  3. If neither of the two above conditions applies, the customer newsletter status is set to STATUS_UNSUBSCRIBED.

I believe there should be an additional elseif condition that checks to see if the newsletter status is STATUS_UNCONFIRMED and the customer has also not confirmed their registration, and if so - it should leave their status as STATUS_UNCONFIRMED. Without this additional check, an unconfirmed customer with unconfirmed newsletter status falls into the last else statement and is set to STATUS_UNSUBSCRIBED.

The solution would look something like this:

        } elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
            $status = self::STATUS_SUBSCRIBED;
            $sendInformationEmail = true;
        } elseif (($this->getStatus() == self::STATUS_NOT_ACTIVE) && ($customerData->getConfirmation() === null)) {
            $status = self::STATUS_NOT_ACTIVE;
        } elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() !== null)) {
            // If the newsletter status is unconfirmed and our customer is unconfirmed, leave them unconfirmed
            $status = self::STATUS_UNCONFIRMED;
        } else {
            $status = self::STATUS_UNSUBSCRIBED;
        }

In testing, this modification caused the process to behave as expected. When the customer registered and chose to subscribe to the newsletter they would first receive the confirmation email, and upon successful confirmation they would then receive the "Newsletter Subscription Success" email, as expected.

Same issue on 2.3.5p1 and type registering of customer is confirmation email

Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

@tuyennn , @dwightc I'm not able to reproduce issue by steps you described on clean 2.4-develop and on the latest composer version 2.4.1
Manual testing scenario:

  1. Set Require Emails Confirmation=Yes
    image
  2. Go to Create New Customer Account page
  3. Check Sign Up for Newsletter checkbox
  4. Fill required fields
  5. Click Create an Account button
    Result:
    :heavy_check_mark: Only confirmation email is sent
    image
    :heavy_check_mark: Customer is not subscribed to newsletter when Confirmed email=Confirmation Required
  1. Click on Confirm Your Account button in confirmation letter

Result:
:heavy_check_mark: Newsletter subscription success and Welcome emails are sent
image
image
:heavy_check_mark: Customer is subscribed to newsletter
image
image

Are you able to reproduce this issue on the latest 2.4-develop branch?

Hello @engcom-Delta, thanks for checking into this.

I'm haven't had time to test it myself yet, but I did quickly look at the \Magento\Newsletter\Model\Subscriber class and I see that there have been significant changes made to it in 2.4.0 so it is likely that the issue has indeed been corrected.

I also looked at the code for 2.3.5p2 and 2.3.6, and I see that in those versions the code has not been changed, so I suspect the issue still exists in the 2.3.x versions.

I will test them when I can and will report back my results.

I was able to test versions 2.3.5p2 and 2.3.6. Here were my results:

2.3.5p2

  • Require Emails Confirmation: YES
  • Customer chooses "Sign Up for Newsletter" during account creation.
  • Result - Not working correctly. Customer receives unsubscribe email at the same time as the confirmation email and even after confirming their email, they are not subscribed.
    image

2.3.6

  • Require Emails Confirmation: YES
  • Customer chooses "Sign Up for Newsletter" during account creation.
  • Result - Working correctly. The customer receives the confirmation email, and after confirmation they receive the subscription and welcome emails.
    image

I was not able to test 2.4+ at this time, but @engcom-Delta has done so above and has indicated that it works correctly there as well.

Hi @krishprakash. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hi @tuyennn. Not able to replicate the issue
Feel free to reopen the issue once you conform that issue is reproduce on latest magento 2.4- develop instance

Was this page helpful?
0 / 5 - 0 ratings