I would like to send customer a link to have their password reseted.

=> Code :

$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory');

$customer->loadByEmail($email);// load customer by email address

    $data= $customer->getData();
    print_r ($data);

However I cannot see any info here like a url that I can generate to then send to the customer.

Is there anyway to do this?

1 Answer 1


I remember you, you asked this on one of my answers before. So here is the details of creating a controller to call the reset password link.

  1. Create routes.xml under app/code/<Vendor_Name>/<Module_Name>/etc/frontend/routes.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
        <router id="standard">
            <route id="<route_id>" frontName="<route_id>">
                <module name="<Vendor_Name>_<Module_Name>" />
  2. Create a controller file. Let's say, you want the URL to me <website_url>/<route_id>/password/reset, then you need to create a file with the path app/code/<Vendor_Name>/<Module_Name>/Controller/Password/Reset.php

    namespace <Vendor_Name>\<Module_Name>\Controller\Password;
    use \Magento\Customer\Model\CustomerFactory;
    use \Magento\Framework\App\Action\Action;
    use \Magento\Framework\App\Action\Context;
    class Reset extends Action
        protected $customerFactory;
        public function __construct(
            Context $context,
            CustomerFactory $customerFactory
            $this->customerFactory = $customerFactory;
        public function execute()
            //This is your code
            $customer = $this->customerFactory->create();
            $data = $customer->getData();

Then, refer to my answer, get the password reset url by changing the codes inside execute(). In case of you forgot the question, here it is: How to generate Password Reset Token in Magento 2

P.S: Avoid using $objectManager directly.

  • ah I see your response now. I'm a bit niave and for me using the $objectManager makes so much sense. I don't get the whole concept of a controller and how to execute it. For example with a objectManger I can just call that within a PHP script and the necessary processing. I think I will have to study this a bit more. For example say I have a boostrap php that I use to do some processing, say create a new user; how would I incorporate this into my code?
    – Ahdee
    Sep 28, 2017 at 15:47
  • Just put $objectManager->get(<class_name>); to __construct instead. For details please see devdocs.magento.com/guides/v2.0/extension-dev-guide/…
    – PY Yick
    Sep 29, 2017 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.