<p>Assuming what you're trying to attach is on the local filesystem, you can see an example of this here: <a href="https://github.com/pixelandtonic/craftnet/blob/master/src/orders/OrderBehavior.php#L160-L182" rel="nofollow noreferrer">https://github.com/pixelandtonic/craftnet/blob/master/src/orders/OrderBehavior.php#L160-L182</a></p>

<p>Essentially, you'd just use <a href="https://www.yiiframework.com/extension/yiisoft/yii2-swiftmailer/doc/api/2.2/yii-swiftmailer-message#attachContent()-detail" rel="nofollow noreferrer">attachContent</a>, but there is also an <a href="https://www.yiiframework.com/extension/yiisoft/yii2-swiftmailer/doc/api/2.2/yii-swiftmailer-message#attach()-detail" rel="nofollow noreferrer">attach</a> method:</p>

<pre><code>-&gt;attachContent($pdf, [
    'fileName' =&gt; $filename,
    'contentType' =&gt; 'application/pdf',
])
</code></pre>

CC BY-SA 4.0
2018-06-15T04:13:17.923Z
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
CC BY-SA 4.0
2018-06-15T22:34:27.830Z
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
CC BY-SA 4.0
2018-06-14T23:50:09.813Z
2019-11-18T05:13:37.507Z
2019-11-18T05:13:37.507Z
Brad Bell
<p>I need to add an "attachment" to an email sent by Craft CMS 3.</p>

<p>I used a custom "Module" for this with a "Model", "Service", "Record" and "Controller"</p>

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

<p><strong>How to send a email with an attachment?</strong></p>

<p>---- Update -----</p>

<p>Here's what I need to do</p>

<p>Example :</p>

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

<p>Prepare the email with the custom "module"</p>

<p><strong>Do I have to upload the file somehow on the server before do the attachement in the email ?</strong></p>

<p>Send the email with the file in attachement to Person B</p>

<craft3><emails><modules>
Craft 3 attachment email
# Craft 3 attachment email

(Asked by: username_0 on 2018-06-14)

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

**Tags:** craft3, emails, modules

---

## 1 answers

### Answer by username_1 on 2018-06-14. Score: 2

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/master/src/orders/OrderBehavior.php#L160-L182
Essentially, you'd just use attachContent, but there is also an attach method:
->attachContent($pdf, [
    'fileName' => $filename,
    'contentType' => 'application/pdf',
])

> **Comments:**
> **username_0**: 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  
> **username_1**: Yes, the file would need to be uploaded to the server somewhere so you could use it as an attachment in your email.  

---

