-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?

3 Answers 3

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()}} @-->
1
  • Have you tried this ? Let me know if its helpful :) Apr 22, 2020 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!

2
  • Did not get you. Please ellaborate.
    – Nafsss
    Apr 22, 2020 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. Apr 22, 2020 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...

3
  • I did not want to add subject as a text field. i am talking about the subject which we receive in email. Subject of the email
    – Nafsss
    Apr 22, 2020 at 5:14
  • try this :- {{var this.getSubject()}} and refer this :- stackoverflow.com/questions/35123779/… Apr 22, 2020 at 5:21
  • Hello @Nafisa check my update answer hope help... Apr 22, 2020 at 5:26

Your Answer

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

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