This module extends the default Magento 2.4.6 contact form functionality by adding an attachment field, allowing users to upload files when submitting a contact request. This is particularly useful for businesses that require additional information or documentation from their customers.
-
Clone the repository to your Magento installation's
app/code/Debuglabs/ContactAttachment
directory:git clone https://github.com/splacento-incomm/Magento2-ContactAttachment.git app/code/Debuglabs/ContactAttachment
-
Enable the module by running the following commands:
bin/magento module:enable Debuglabs_ContactAttachment bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
-
Allowed File Types and Maximum File Size:
- The configuration for allowed file types and maximum file size can be found in the Magento admin panel under:
STORES > Configuration > General > Contact Attachment
- Allowed file types should be specified as a comma-separated list (e.g.,
.png, .jpg, .gif, .jpeg
). - Maximum file size should be specified in megabytes (MB).
- The configuration for allowed file types and maximum file size can be found in the Magento admin panel under:
-
Create or Update Contact Us Email Template:
-
You need to create a new contact us email template. This can be done in the Magento admin panel under:
Marketing > Email Templates
-
After creating the email template, set it up as the email template for the contact form in:
STORES > Configuration > General > Contacts > Email Options > Email Template
-
If you have your own or already defined email template, add the following code to include the attachment field in the email:
<tr> <td><strong>{{trans "Attachment"}}</strong></td> <td>{{var data.attachment}}</td> </tr>
-
-
Editing Custom Fields:
- If you need to add custom fields to the contact form, edit the form template located at:
view/frontend/templates/form.phtml
- If you need to add custom fields to the contact form, edit the form template located at:
After following the installation and configuration steps, your Magento 2 contact form will include a file upload field, allowing users to attach files to their contact submissions.
This module was inspired by a solution provided by Akash Malik on the Magento Stack Exchange.
This project is licensed under the MIT License.