How to change custom sender mail id in magento 2

In Magento 2, you can change the custom sender mail ID by modifying the send_email method in the Magento\Framework\Mail\Template class. Here are the steps:

Method 1: Using Magento's built-in configuration

  1. Go to Stores > Configuration > Advanced > System > Mail > Sendmail
  2. In the From Email field, enter the custom sender mail ID you want to use.
  3. Save the configuration.

Method 2: Modifying the send_email method

  1. Create a custom module by creating a new directory in app/code and adding a registration.php file with the following content:
    <?php
    \Magento\Framework\Component\ComponentRegistrar::register(
     \Magento\Framework\Component\ComponentRegistrar::MODULE,
     'YourModule',
     __DIR__
    );
  2. Create a etc/module.xml file in the same directory with the following content:
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/moduleconfig.xsd">
     <module name="YourModule" setup_version="1.0.0">
         <sequence>
             <module name="MagentoFramework"/>
         </sequence>
     </module>
    </config>
  3. Create a etc/email.xml file in the same directory with the following content:
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/email.xsd">
     <template>
         <send_email>
             <arguments>
                 <argument name="from_email" xsi:type="string">[email protected]</argument>
             </arguments>
         </send_email>
     </template>
    </config>
  4. In the from_email argument, enter the custom sender mail ID you want to use.
  5. Run the following command to deploy the changes:
    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy
  6. Clear the cache by running:
    php bin/magento cache:clean

After following these steps, the custom sender mail ID should be used when sending emails from your Magento 2 store.