19 declare(strict_types=1);
29 $mail =
new PHPMailer();
38 protected function setMailer(PHPMailer $mailer): void
61 foreach ($mail->
getTo() as $recipients) {
62 $recipient_pieces = array_filter(
array_map(
'trim', explode(
',', $recipients)));
63 foreach ($recipient_pieces as $recipient) {
64 if (!$this->
getMailer()->addAddress($recipient)) {
70 foreach ($mail->
getCc() as $carbon_copies) {
71 $cc_pieces = array_filter(
array_map(
'trim', explode(
',', $carbon_copies)));
72 foreach ($cc_pieces as $carbon_copy) {
73 if (!$this->
getMailer()->addCC($carbon_copy)) {
79 foreach ($mail->
getBcc() as $blind_carbon_copies) {
80 $bcc_pieces = array_filter(
array_map(
'trim', explode(
',', $blind_carbon_copies)));
81 foreach ($bcc_pieces as $blind_carbon_copy) {
82 if (!$this->
getMailer()->addBCC($blind_carbon_copy)) {
90 if ($mail->
getFrom()->hasReplyToAddress() && !$this->
getMailer()->addReplyTo(
91 $mail->
getFrom()->getReplyToAddress(),
92 $mail->
getFrom()->getReplyToName()
96 if ($mail->
getFrom()->hasEnvelopFromAddress()) {
100 if (!$this->
getMailer()->setFrom($mail->
getFrom()->getFromAddress(), $mail->
getFrom()->getFromName(),
false)) {
105 if (!$this->
getMailer()->addAttachment($attachment[
'path'], $attachment[
'name'])) {
111 if (!$this->
getMailer()->addEmbeddedImage($image[
'path'], $image[
'cid'], $image[
'name'])) {
126 "Trying to delegate external email delivery:" .
127 " Initiated by: %s (%s) " .
128 "| To: %s | CC: %s | BCC: %s | Subject: %s " .
130 "| ReplyTo: %s / %s " .
131 "| EnvelopeFrom: %s",
134 implode(
', ', $mail->
getTo()),
135 implode(
', ', $mail->
getCc()),
136 implode(
', ', $mail->
getBcc()),
138 $mail->
getFrom()->getFromAddress(),
139 $mail->
getFrom()->getFromName(),
140 $mail->
getFrom()->getReplyToAddress(),
141 $mail->
getFrom()->getReplyToName(),
142 $mail->
getFrom()->getEnvelopFromAddress()
146 ->debug(sprintf(
"Mail Alternative Body: %s", $this->
getMailer()->AltBody));
148 ->debug(sprintf(
"Mail Body: %s", $this->
getMailer()->Body));
152 $this->mailer->Debugoutput =
static function (
string $message, $level):
void {
154 strpos($message,
'Invalid address') ||
155 strpos($message,
'Message body empty')
167 ->info(
'Successfully delegated external mail delivery');
169 if ($this->
getMailer()->ErrorInfo !==
'') {
171 '... with most recent errors: %s',
177 'Could not deliver external email: %s',
182 $this->event_handler->raise(
'components/ILIAS/Mail',
'externalEmailDelegated', [
static getLogger(string $a_component_id)
Get component logger.
setMailer(PHPMailer $mailer)
__construct(protected ilSetting $settings, private readonly ilAppEventHandler $event_handler)