Conversation
|
@CamilleBeau FYI here is how I had implemented it. I really don't recall why I did moved away from the Email class but I rememebr trying and giving up at a certain point. |
|
|
||
| foreach ($attachments as $file) { | ||
|
|
||
| if (!file_exists($file['path'])) { |
There was a problem hiding this comment.
Should probably throw an exception or at least log an error if it's trying to email a file that doesn't exist or can't be accessed?
| ); | ||
|
|
||
| $filename = $file['name'] ?? basename($file['path']); | ||
| $filetype = $file['type'] ?? 'application/octet-stream'; |
There was a problem hiding this comment.
Since you're passing filename/paths you can try mime_content_type before falling back on application/octet-stream
| string $bcc = '', | ||
| string $type="text/plain" | ||
| string $type="text/plain", | ||
| array $atachments = [] |
There was a problem hiding this comment.
For some reason GitHub isn't giving me the "suggest changes" option but attachments is spelled wrong (so I'm not sure how this is working because it's spelled properly in the code..)
|
|
||
| // Use chunk_split for proper line length | ||
| $fileContent = chunk_split( | ||
| base64_encode(file_get_contents($file['path'])) |
There was a problem hiding this comment.
I find the format of $file hard to follow because it's not documented anywhere.
Does the array format have any fields that couldn't be derived from using an iterable of \SplFileInfo? If not, I recommend using that.. if so, maybe you should add an EmailAttachment class where the format could be more explicit.
Brief summary of changes
This PR adds to the Email.class.inc library file to be able to add attachments to emails sent by LORIS.
This is done by detecting whether an array of attachments was added, and if so, changing the Content-Type to multi-part and adding each attachment individually. If no attachments are passed as an argument, then the Email class continues as it did before.
Testing instructions (if applicable)
Link(s) to related issue(s)