Magento2 I want to send a thankyou email to customer after filling up the Contact Us form.

In order to achieve this I used below link custom mode

How to send an Email confirmation after contact us

But I am facing a strange issue, as a customer, I received the thankyou email properly but the admin email id present under Store > Configuration > General > Contacts > Send Emails to also received the Thankyou email.

In short,

Email 1: Admin received Form data email(mentioned under Send Emails to)

Email 2: Customer received Thankyou mail

Email 3: Admin received Thankyou mail(mentioned under Send Emails to)

Email 3 is incorrect, this should not have being received.

Any suggestions will be appreciated. Thanks in advance.

  • Please be aware the reason this doesnt happen by default is because someone can enter any email address and your server will send the confirmation to that address. Therefore without captcha you will soon be sending a lot of spam. Definitely don't repeat back the content as shown in that other post. Apr 28, 2020 at 18:37

1 Answer 1


I think you want something like this


Much of the hard work is done by the plugin


    public function afterSend(
        \Magento\Contact\Model\Mail $subject,
    ) {
        if (!$this->helper->getConfirmation()) {

        /** @see \Magento\Contact\Controller\Index\Post::validatedParams() */
        $replyToName = !empty($replyTo['data']['name']) ? $replyTo['data']['name'] : null;
        $replyToEmail = !empty($replyTo['data']['email']) ? $replyTo['data']['email'] : null;

        // $this->contactsConfig->emailSender(); string
        // $this->contactsConfig->emailRecipient(); email

        try {
            $transport = $this->transportBuilder
                        'area' => Area::AREA_FRONTEND,
                        'store' => $this->storeManager->getStore()->getId()
                    'email' => $this->contactsConfig->emailRecipient(),
                    'name' => $this->contactsConfig->emailSender()

        } finally {
        return $result;

Email template markup is here


<!--@subject {{trans "Thanks for getting in touch"}} @-->
<!--@vars {
"var data.comment":"Comment",
"var data.email":"Sender Email",
"var data.name":"Sender Name",
"var data.telephone":"Sender Telephone",
} @-->

{{template config_path="design/email/header_template"}}

<table class="message-details">
        <td>Thanks for reaching out to us {{var data.name}}</strong></td>
        <td>One of the team will be in touch soon.</td>

{{template config_path="design/email/footer_template"}}
  • Hi, The module is working fine but I am facing an issue that I have already used this <type name="Magento\Contact\Controller\Index\Post"> <plugin name="custom_contact_action" type="Vendor\ContactAutoRespond\Plugin\Post"/> </type> & so the mail doesn't get send. If I remove above code then it is working fine. I want controller plugin & Model Plugin to be used together
    – Arjun
    Apr 29, 2020 at 6:18
  • You are going to have to merge the logic from both extensions into a single extension and possibly take one out. It's difficult but it happens. Apr 29, 2020 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.