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
- Go to
Stores
>Configuration
>Advanced
>System
>Mail
>Sendmail
- In the
From Email
field, enter the custom sender mail ID you want to use. - Save the configuration.
Method 2: Modifying the send_email
method
- Create a custom module by creating a new directory in
app/code
and adding aregistration.php
file with the following content:<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'YourModule', __DIR__ );
- 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>
- 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>
- In the
from_email
argument, enter the custom sender mail ID you want to use. - Run the following command to deploy the changes:
php bin/magento setup:upgrade php bin/magento setup:static-content:deploy
- 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.