Change 'From' field of magento contact form email to the sender

Change 'From' field of magento contact form email to the sender

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Change 'From' field of magento contact form email to the sender

Changing the ‘From’ Field of Magento Contact Form Emails

When working with Magento’s built-in contact form, you might find that the email sent to store owners is always from the generic “from” address configured in your admin panel. However, what if you want this email to come from the actual sender—the customer who filled out the form?

Understanding the Default Behavior

By default, Magento uses the configuration set under Stores > Configuration > General > Store Email Addresses for all outgoing emails, including contact form submissions. This is a security measure to ensure that your store’s email address remains professional and consistent.

However, there are cases where you might want to override this behavior. For example, if you’re running an e-commerce platform with user accounts, it would be more intuitive for customers to receive replies from their own email addresses instead of a generic “no-reply” account.

Changing the ‘From’ Field: A Step-by-Step Guide

Step 1: Override the Contact Form Block

The first step is to override the contact form block. This involves creating a local copy of the Mage_Contact_Block_Form file in your custom theme directory (app/design/frontend/{package}/{theme}/template/contact/form.phtml).

# Path
app/design/frontend/{package}/{theme}/template/contact/

Step 2: Modify the Post Action

In the overridden form.phtml file, locate the line that defines the post action for the form. It should look something like this:

<form id="contactForm" action="<?php echo $this->getPostActionUrl() ?>" method="post">

Change it to:

<form id="contactForm" action="<?php echo $this->getPostActionUrl() ?>" method="post">
  <input type="hidden" name="email" value="<?php echo $this->getEmailValue(); ?>">
</form>

Step 3: Create a Custom Email Value Function

Next, you need to create a custom function in your theme’s local module file (app/code/local/{namespace}/{your_module}/Block/Form.php) that will return the email address entered by the customer.

public function getEmailValue()
{
    $email = Mage::getSingleton('core/session')->getContactFormEmail();
    return $email;
}

Step 4: Capture and Store the Email Address

In the Mage_Contact_Block_Form file (the original one, not your override), find the line that handles the form submission:

$this->getRequest()->setPost('email', $_POST['email']);

Just below this line, add:

Mage::getSingleton('core/session')->setContactFormEmail($_POST['email']);

This code captures the email address from the post data and stores it in the session.

Note on Security

Be aware that by changing the “from” address, you are potentially exposing your customers to reply attacks. Always ensure that any emails sent out of this system have proper anti-spam headers set and are thoroughly validated before being processed or sent.

Conclusion

Changing the “from” field in Magento’s contact form email requires a combination of theme overrides and custom module development. While it may seem complex, following the steps outlined above should allow you to achieve your goal.

Remember, always test changes like this thoroughly on a staging environment before deploying them to production. If you’re feeling unsure about any part of the process, don’t hesitate to reach out to our team at Laravel Company for expert guidance and support.

Security Themes Admin Configuration

Our network