translation = $translation; $this->view = $view; } /** * @param string|string[]|User $to * @param array $data */ public function sendViewTranslated( string|array|User $to, string $subject, string $template, array $data = [], ?string $locale = null ): void { if ($to instanceof User) { $locale = $locale ?: $to->settings->language; $to = $to->contact->email ?: $to->email; } $activeLocale = null; if ( $locale && $this->translation && isset($this->translation->getLocales()[$locale]) ) { $activeLocale = $this->translation->getLocale(); $this->translation->setLocale($locale); } $subject = $this->translation ? $this->translation->translate($subject, $data) : $subject; $this->sendView($to, $subject, $template, $data); if ($activeLocale) { $this->translation->setLocale($activeLocale); } } /** * Send a template * * @param string|string[] $to * @param array $data */ public function sendView(string|array $to, string $subject, string $template, array $data = []): void { $body = $this->view->render($template, $data); $this->send($to, $subject, $body); } /** * Send the mail * * @param string|string[] $to */ public function send(string|array $to, string $subject, string $body): void { if ($this->subjectPrefix) { $subject = sprintf('[%s] %s', $this->subjectPrefix, trim($subject)); } parent::send($to, $subject, $body); } public function getSubjectPrefix(): string { return $this->subjectPrefix; } public function setSubjectPrefix(string $subjectPrefix): void { $this->subjectPrefix = $subjectPrefix; } }