I need to add an "attachment" to an email sent by Craft CMS 3.

I used a custom "Module" for this with a "Model", "Service", "Record" and "Controller"

I did some research but did not find any clear answers on how to do it.

How to send a email with an attachment?

---- Update -----

Here's what I need to do

Example :

Person A Fill the form with file a file ( like doc, pdf etc... )

Prepare the email with the custom "module"

Do I have to upload the file somehow on the server before do the attachement in the email ?

Send the email with the file in attachement to Person B

Assuming what you're trying to attach is on the local filesystem, you can see an example of this here: https://github.com/pixelandtonic/craftnet/blob/develop/src/orders/OrderBehavior.php#L152-L170

Essentially, you'd just use attachContent, but there is also an attach method:

->attachContent($pdf, [
    'fileName' => $filename,
    'contentType' => 'application/pdf',
])
  • Here's what I need to do Example : Person A Fill the form with a file ( like doc, pdf etc... ) Prepare the email with the custom "module" Do I have to upload the file somehow on the server before do the attachement in the email ? Send the email with the file in attachement to Person B – Lofka Jun 15 at 4:13
  • Yes, the file would need to be uploaded to the server somewhere so you could use it as an attachment in your email. – Brad Bell Jun 15 at 22:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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