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?