S
S
Sergey Konovalenko2018-11-01 14:02:30
CMS
Sergey Konovalenko, 2018-11-01 14:02:30

WordPress, how to send emails with attachments, while allowing the site user to manage them through the admin panel?

I have a success.php form handler located at the root of my WordPress installation. In the letter, in addition to the text, PDF files should be sent as an attachment.
The client through the admin panel should be able to manage these files that are sent (change, add, etc.).
Do I understand correctly that for this I need to pass the full path to the files in $_POST, and then use them in the handler?
I tried to make a hidden input in the form, and display the path to the file in value:
5bdadcb6eac32352941888.png
For arbitrary fields, I used the ACF plugin, a field with the "File" type, which returns a link to the file.
Then, in the handler, I tried to assign this path to the $attachments variable:
5bdadd00bc6dc625434045.jpeg
but in the letter the file for some reason does not come as an attachment, only text information. At least the path to the file itself: $file = htmlspecialchars($_POST["file"]); successfully arrives at the handler.
And if you write like this, then the file successfully comes as an attachment to the mail:
5bdadd3575268584113626.jpeg
Tell me, how can I send files by mail and so that the client can manage these files through the admin panel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Konovalenko, 2018-11-01
@sergeykonovalenko

You need to pass the attachment ID and use the get_attached_file() function , which gets the absolute (server) path of the attachment (attached file) by the passed attachment ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question