Published on 03/02/2021
Published by Pratik Takle
Send attachment in mail (direct using absolute file path)
- In requirements, there can be a case where you need to send attachment in mail.
- Where as this attachment can be static which means already upload in media.
- or you can make array of filepaths by fetching them through meta, collection meta or any specified space.
- This filepath plays vital role in mail send.
- Consider following code.
-
123456789[template.set_array email][attachments][file_path new]{absolute_path_of_file}[/file_path][/attachments][/template.set_array]
- In above snippet,
- attachment array consists of filepath key
- this filepath can be one or multiple depending upon you attachment send requirement.
- remember to mention absolute path of file as filepath value
- for ex:
- absolute path of xyz.pdf on https://www.getawesomestudio.com/ will be
- /var/www/getawesomestudio.com/htdocs/wp-content/uploads/{year}/{month}/xyz.pdf
- wp-content/uploads/{year}/{month}/xyz.pdf – this part you can copy from file URL itself.
- Whole Email snippet will be like
-
1234567891011121314151617[templates.add main][template.set_array email][attachments][file_path new]/var/www/getawesomestudio.com/htdocs/wp-content/uploads/2020/02/xyz.pdf[/file_path][/attachments][/template.set_array][do.notify_data][aw2.set notify_data.name="Test user" /][notification_service.send email="{template.email}" log="yes"template_slug="sample-email" email_layout='common_layout'set='module.returnval' /][/do.notify_data][/templates.add]
- Study above code and try it.
- Happy coding!