-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from xedi/feat/attach_files
Added ability to add attachments to emails
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Xedi\SendGrid\Mail\Concerns; | ||
|
||
/** | ||
* HasAttachment Concern | ||
* | ||
* @package Xedi\SendGrid\Mail\Concerns | ||
* @author Adam Witeszczak <adam@xedi.com> | ||
*/ | ||
trait HasAttachment | ||
{ | ||
protected $attachments = []; | ||
|
||
/** | ||
* Set Attachment | ||
* | ||
* @param $attachment string attachment file as string | ||
* @param $mime_type string mime type | ||
* @param $name string name | ||
* | ||
* @return $this | ||
*/ | ||
public function setAttachment($attachment, $mime_type, $name) | ||
{ | ||
$toAttach = new \StdClass(); | ||
$toAttach->content = base64_encode($attachment); | ||
$toAttach->type = $mime_type; | ||
$toAttach->filename = $name; | ||
$toAttach->disposition = 'attachment'; | ||
$this->attachments[] = $toAttach; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Has Attachment | ||
* | ||
* @return bool | ||
*/ | ||
public function hasAttachment(): bool | ||
{ | ||
return count($this->attachments) > 0; | ||
} | ||
|
||
/** | ||
* Build the Attachment data for the API Request | ||
* | ||
* @return string API data | ||
*/ | ||
public function buildAttachment(): array | ||
{ | ||
return [ | ||
'attachments' => $this->attachments | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters