-1

I have customised the Email template of Contact Us email with adding some new fields into it. However, i want to know where is the option to add Default subject to the email. When my user submits contact us form, i receive email with blank subject. Let me know how can i add subject?

1

You can write email subject to in your email .html file

<!--@subject {{trans "Your Subject Write Here "}}  @-->

You can pass subject dynamic by follow below example

<!--@subject {{trans "Welcome to %store_name" store_name=$store.getFrontendName()}} @-->
| improve this answer | |
  • Have you tried this ? Let me know if its helpful :) – Hamendra Sunthwal Apr 22 at 5:40
0

You can add subject in you email template file by add below the line on top of the file content:

<!--@subject Subject Text  @-->

Hope it helps!

| improve this answer | |
  • Did not get you. Please ellaborate. – Steven Harris Apr 22 at 5:15
  • @Nafisa Just add the above-given line in your template file first line and replace your custom text with "Subject text" to set the default subject. – Technocracker Apr 22 at 5:30
0

I tried to easy way Please check follow setps

First open form.phtml file located in your theme

/magento_root/app/design/frontend/VENDER_NAME/YOUR_THEME/Magento_Contact/templates/form.phtml, then add subject field to this contact form:

<div class="field subject required">
    <label class="label" for="subject"><span><?php /* @escapeNotVerified */ echo __('Subject') ?></span></label>
    <div class="control">
        <input name="subject" id="subject" title="<?php /* @escapeNotVerified */ echo __('Subject') ?>" value="" class="input-text" type="text" data-validate="{required:true}"/>
    </div>
</div>

Add the above field in the form.

As far as Magento is concerned, it doesn't care what fields we add to this form. It is written in such a way that it accepts all of the field posted for processing and send that out to the transactional e-mail form that you create. Now, go to MARKETING > Communication > Email Templates in the Magento Admin section. Click "Add New Template" and from the "Template" dropdown box select "Contact Form" then "Load Template". Under template content you will see:

{{trans "Name: %name" name=$data.name}}
{{trans "Email: %email" email=$data.email}}
{{trans "Phone Number: %telephone" telephone=$data.telephone}}
{{trans "Comment: %comment" comment=$data.comment}}

Add your new field before Name: {{trans "Name: %name" name=$data.name}} so that now it should looks like this:

{{trans "Subject: %subject" subject=$data.subject}}
{{trans "Name: %name" name=$data.name}}
{{trans "Email: %email" email=$data.email}}
{{trans "Phone Number: %telephone" telephone=$data.telephone}}
{{trans "Comment: %comment" comment=$data.comment}}

And save template. Now we need to tell Magento to use this new template for the Contact form. Go to STORES > Settings > Configuration > General > Contacts and select "Contacts". Under "Email Options", select your new template under the "Email Options" > "Email Template" dropdown box. Click on Save Button.

And check this more information :-

Add custom field to contact form Magento 2?

You can write email subject to in your email .html file

<!--@subject {{trans "Welcome to %store_name" store_name=$store.getFrontendName()}} @-->

Thanks...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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