Search code examples
emailtransactionssendmailmagento2newsletter

Magento 2.0.7: Something went wrong with the subscription.


get error whe subscription Newsletter. How can fix? enter image description here


Solution

  • Here is the problem and the solution to this bug:

    When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.

    The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.

    You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();

       try {
                $this->save();
                if($isConfirmNeed === true && $isOwnSubscribes === false)
                {
                    $this->sendConfirmationRequestEmail();
                } else {
                    $this->sendConfirmationSuccessEmail();
                }
                return $this->getStatus();
            } catch (\Exception $e) {
                throw new \Exception($e->getMessage());
            }
    

    I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.