0

what is the best way to add a File Upload field in the Contact Page? I want to give users option to upload a file. I try this module but is not work on my 2.3.3 Magento version.

Thank you

  • I spent some time on this to see if I could figure it out. Magento team have really messed around with email logic. I thought maybe it was because of the patch magento.stackexchange.com/questions/294379/… but it's still not working on 2.3.3. I've seen this but no idea if it works meetanshi.com/blog/add-attachments-with-email-in-magento-2-3-x I've run out of time on this. In the meantime I've applied some fixes in my repo but still not working on 2.3.3. Good luck. – Dominic Xigen Feb 14 at 1:25
  • @DominicXigen thank you so much, I have a question, can you give me an example how we can use the the meetanshi blog article in the contact page? – Robert Feb 14 at 6:58
  • check v1.0.6. I'm not 100% my dev setup isn't sending contact form emails on 2.3.3 regardless of extension enabled/disabled but I've basically implemented their suggestion. Let me know how you get on. – Dominic Xigen Feb 14 at 14:05
  • @DominicXigen Hi I'll test it in the morning is very late here, but thank you very much for your efforts. I really appreciate your help. – Robert Feb 14 at 19:01
  • @DominicXigen Hi, I add your latest version, but after I press the Submit button I have this message: "Incorrect reCAPTCHA" do you have any idea how we can add this Google Recaptcha too? – Robert Feb 15 at 8:58
-1

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">
<p id="file_error" class="message-error error message" style="display:none;">
    File is too large
</p>
    <label class="label" for="subject"><span><?php /* @escapeNotVerified */ echo __('Attachment') ?></span></label>
    <div class="control">
        <input name="subject" id="file-btn" accept=".pdf, .png, .jpg, .gif, .docx, .jpeg/*" name="document" type="file" value="" 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 for Attachment and this code :-

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

<table class="message-details">
    <tr>
        <td><strong>{{trans "Name"}}</strong></td>
        <td>{{var data.name}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Email"}}</strong></td>
        <td>{{var data.email}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Phone"}}</strong></td>
        <td>{{var data.telephone}}</td>
    </tr>
<tr>
           <td><strong>{{trans "Subject"}}</strong></td>
        <td>{{var data.subject}}</td>
    </tr>
</table>
<p><strong>{{trans "Message"}}</strong></p>
<p>{{var data.comment}}</p>

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

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 last check you contact page.

Hope help you

Thanks.

|improve this answer|||||
  • thank you for your answer, and is work like this? I mean you receive that file atachment in email? You have test this code and it send the file atachment ? – Robert Feb 13 at 21:06
  • Yes , @Robert i have tested and worked me – Mohit Patel Feb 14 at 14:23
  • Hi, I just test what you add here but in the email is not any attachment ... can you check again? – Robert Feb 15 at 9:06
  • Hello @Robert sorry for late but find solution Please install the module and get attachment options and received email Please check Screen-short :- prnt.sc/r4dl95 Extensions :- github.com/DominicWatts/ContactAttachment – Mohit Patel Feb 19 at 4:06
  • Note this I haven't been able to test 2.3.3 or later in live environment yet so use this extensions only 2.3.3 – Mohit Patel Feb 19 at 4:14

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.