Merge branch 'refactor-usage-sn' into feat-mail-template-override-ur
This commit is contained in:
commit
e4467521f8
|
@ -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())
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue