Domanda

I want to send all the user the reset password email, we have over 6000 user so it can't be done by hand.

I found this script from this website:

    <?php 
    //place this before any script you want to calculate time
    $time_start = microtime(true);

    // MAGENTO START
    include('app/bootstrap.php');

    use Magento\Framework\App\Bootstrap;
    use Magento\Customer\Api\AccountManagementInterface;
    use Magento\Customer\Model\AccountManagement;

    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();

    $state = $objectManager->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');

    $_customers = $objectManager->create('Magento\Customer\Api\AccountManagementInterface');
    $customerCollection = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
    $customerCollection->load();
    $i = 0;
    foreach ($customerCollection as $customers) {

        $email = $customers->getData('email');

        try {
                $_customers->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
            } catch (NoSuchEntityException $e) {
                // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
            } catch (\Exception $exception) {
                echo __('We\'re unable to send the password reset email.');
            }
            echo "<pre>";
            echo $i . " Email :-" . $email . " Mail Sent";
        $i++;
    }
?>

But that isn't working :(

Is there a way to make this script work or maybe another solution?

È stato utile?

Soluzione

I printed the exception message in the code,

 try {
                $_customers->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
            } catch (NoSuchEntityException $e) {
                // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
            } catch (\Exception $exception) {
                echo __($exception->getMessage());
            }
            echo "<pre>";
            echo $i . " Email :-" . $email . " Mail Sent";
        $i++;

I got the error like this We received too many requests for password resets.

For this error you need to disable the password protection in magento2 backend customer configuration.

I have disabled password protection from Configuration -> Customers -> customer configuration. so it look like this in my admin,

enter image description here

set the password protection to none and try it. After the password sent, please revert back to original configuration for security purpose

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top