cancel
Showing results for 
Search instead for 
Did you mean: 

Contact Form - One e-mail for each department/subject

Contact Form - One e-mail for each department/subject

Dear Community,

 

I'm trying to introduce a feature in my website's contact form that allows the user to contact different e-mails depending on the subject.

 

This is the actual contact form:

 

a.png

 

I need an extra field named "Subject" with two options:

 

"General Discussion" - email1@domain.com

"Customer Issues" - email2@domain.com

 

How can I do that?

 

Thank you!

5 REPLIES 5

Re: Contact Form - One e-mail for each department/subject

You need to add new field into your contact form.phtml

<select style="width:271px;" name="dep_subject" id="dep_subject">
			  <option value=""><?php echo __('') ?></option>
			  <option value=""><?php echo __('') ?></option>
</select>

Override contact controller create di.xml file
file path :- app/code/Namespace/Yourmodule/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
  <preference for="Magento\Contact\Controller\Index\Post" type="Namespace\Yourmodule\Controller\Index\Post" /> 
</config>

Create Post.php or you copt Post.php file from Magento\Contact\Controller\Index\Post.php file
File path:- app/code/Namespace/Yourmodule/Controller/Index/Post.php

<?php
namespace Namespace\Yourmodule\Controller\Index;

class Post extends \Magento\Contact\Controller\Index
{

    public function execute()
    {
        $post = $this->getRequest()->getPostValue();
        if (!$post) {
            $this->_redirect('*/*/');
            return;
        }

        $this->inlineTranslation->suspend();
        try {
            $postObject = new \Magento\Framework\DataObject();
            $postObject->setData($post);

            $error = false;

            if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
                $error = true;
            }
            if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }
            if (\Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                $error = true;
            }
            if ($error) {
                throw new \Exception();
            }
	  
	  // Write your suject to send email logic
           
        } catch (\Exception $e) {
            $this->inlineTranslation->resume();
            $this->messageManager->addError(
                __('We can\'t process your request right now. Sorry, that\'s all we know.')
            );
            $this->_redirect('contact/index');
            return;
        }
    }
}

Re: Contact Form - One e-mail for each department/subject

Do I have to create those folders named "Namespace", "Yourmodule", ...?

Re: Contact Form - One e-mail for each department/subject

Hi Tierri,

 

This is for magento 2 because write question in magento 2 section but your site magento1.9.2 version 

This solution is not for magento your current version.

Re: Contact Form - One e-mail for each department/subject

Then how can i do in magento 1.9 version?

isn't there a solution about that? 

Re: Contact Form - One e-mail for each department/subject

Hey @xzxzxzxyy

The best way would be to ask the question in the right category on Magento 1 Smiley Wink

Was my answer helpful? You can accept it as a solution.
230+ professional extensions for M1 & M2 with free lifetime updates!