Setting up mail forms via SMTP in Magento 2.4.x
This tutorial presents how to set up a mail form via SMTP authentication in the Magento application.
Introduction
This tutorial explains how to set up email forms using the SMTP protocol in Magento 2.4.x.
Requirements:
- A valid VPS hosting account and domain
- The Magento application installed on hosting, access to its administration panel, and Terminal access through cPanel
- A mailbox created in the hosting panel that will be used for sending emails
Steps to follow:
Initially, Magento does not come in its construction with the SMTP mail function installed. Therefore, it will be necessary to separately install a module capable of implementing this function.
- Access the cPanel hosting administration panel and then the Terminal plugin or SSH console. Navigate to the path
/home/user/public_html
or to the folder where the application is installed. - A user and a password in the form of keys generated from the Mageplaza platform are required, where you must have an account created.
- Generate a pair of access keys by pressing the Create new access keys button.
- The keys are generated automatically, representing the user and password in the form:
- If the generated keys are not functional, you can use the test keys provided by Mageplaza for the free modules.
User: 4e947606bf2552e4dad4910bd1928b08
Pass: 30ff4445ebad7885b012fdc667487096
- From the SSH terminal, install the SMTP module by running the commands:
composer require mageplaza/module-smtp
The console will request the previously generated keys.
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
- Access the Magento admin interface to configure the SMTP module.
- From the left menu, select Stores -> Settings -> Configurations.
- From the Mageplaza Extensions menu, select the SMTP sub-menu.
- Activate the SMTP extension by filling in the name, email address, and clicking Activate Now in the Module Information section.
- In the General Configuration section:
1. Enable Mageplaza SMTP: Select Yes.
2. Log Emails: Select Yes to keep a log.
3. Clean Email Log Every: Set the number of days to retain the log.
4. Blacklist: Enter addresses or patterns excluded from sending.
- In the SMTP Configuration Options section:
1. Host: Fill in the email server (e.g., mail.domain.com).
2. Port: Fill in the secure port 465.
3. Protocol: Choose SSL.
4. Authentication: Select LOGIN.
5. Username: Fill in the email account user.
6. Password: Fill in the email box password.
7. Return-Path Email: Enter the response address (identical to the sending address).
- Test the settings in the Send Test Email section.
- Press Save Config to save the configurations.