-
Notifications
You must be signed in to change notification settings - Fork 195
Comments
[Email] Add attachment functionality#10374
Conversation
ridz1208
commented
Feb 19, 2026
@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.
//email
$config =& NDB_Config::singleton();
$from = ($config->getSetting('mail'))['From'];
$email = new PHPMailer();
$email->SetFrom($from);
$email->Subject = "THIS IS THE SUBJECT LINE";
$email->Body = "THIS IS THE BODY";
$recipientEmail = $config->getSetting("mailto");
$email->AddAddress($recipientEmail);
$email->AddAddress("rida.abou-haidar@mcin.ca");
$email->AddAttachment( $EOS_path , $EOS_file);
$email->AddAttachment( $o_path , $o_file);
$email->Send();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're passing filename/paths you can try mime_content_type before falling back on application/octet-stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)