1
0
Fork 0
mirror of synced 2024-07-05 22:51:24 +12:00

Merge branch 'refactor-usage-sn' into feat-mail-template-override-ur

This commit is contained in:
Damodar Lohani 2023-12-09 07:36:11 +01:00 committed by GitHub
commit e4467521f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -14,6 +14,7 @@ class Mail extends Event
protected array $smtp = []; protected array $smtp = [];
protected array $variables = []; protected array $variables = [];
protected string $bodyTemplate = ''; protected string $bodyTemplate = '';
protected array $attachment = [];
public function __construct(protected Connection $connection) public function __construct(protected Connection $connection)
{ {
@ -337,6 +338,22 @@ class Mail extends Event
return $this; return $this;
} }
public function setAttachment(string $content, string $filename, string $encoding = 'base64', string $type = 'plain/text')
{
$this->attachment = [
'content' => base64_encode($content),
'filename' => $filename,
'encoding' => $encoding,
'type' => $type,
];
return $this;
}
public function getAttachment(): array
{
return $this->attachment;
}
/** /**
* Executes the event and sends it to the mails worker. * Executes the event and sends it to the mails worker.
* *
@ -355,6 +372,7 @@ class Mail extends Event
'body' => $this->body, 'body' => $this->body,
'smtp' => $this->smtp, 'smtp' => $this->smtp,
'variables' => $this->variables, 'variables' => $this->variables,
'attachment' => $this->attachment,
'events' => Event::generateEvents($this->getEvent(), $this->getParams()) 'events' => Event::generateEvents($this->getEvent(), $this->getParams())
]); ]);
} }

View file

@ -59,6 +59,7 @@ class Mails extends Action
$variables = $payload['variables']; $variables = $payload['variables'];
$name = $payload['name']; $name = $payload['name'];
$body = $payload['body']; $body = $payload['body'];
$attachment = $payload['attachment'] ?? [];
$bodyTemplate = $payload['bodyTemplate']; $bodyTemplate = $payload['bodyTemplate'];
if(empty($bodyTemplate)) { if(empty($bodyTemplate)) {
$bodyTemplate = __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; $bodyTemplate = __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl';
@ -92,6 +93,14 @@ class Mails extends Action
$mail->Subject = $subject; $mail->Subject = $subject;
$mail->Body = $body; $mail->Body = $body;
$mail->AltBody = \strip_tags($body); $mail->AltBody = \strip_tags($body);
if (!empty($attachment['content'] ?? '')) {
$mail->AddStringAttachment(
base64_decode($attachment['content']),
$attachment['filename'] ?? 'unknown.file',
$attachment['encoding'] ?? PHPMailer::ENCODING_BASE64,
$attachment['type'] ?? 'plain/text'
);
}
try { try {
$mail->send(); $mail->send();