$name) { $to = new SymfonyAddress($email, $name); break; } $message = new SymfonyMessage; $message->from(new SymfonyAddress( self::$senderAddr, self::$senderName )); if($bcc) $message->bcc($to); else $message->to($to); $message->subject(trim($subject)); $message->text(trim($contents)); try { self::getTransport()->send($message); return true; } catch(TransportExceptionInterface $ex) { if(MSZ_DEBUG) throw $ex; return false; } } public static function template(string $name, array $vars = []): array { $path = sprintf(self::TEMPLATE_PATH, $name); if(!is_file($path)) throw new InvalidArgumentException('Invalid e-mail template name.'); $tpl = file_get_contents($path); // Normalise newlines $tpl = str_replace("\n", "\r\n", str_replace("\r\n", "\n", $tpl)); foreach($vars as $key => $val) $tpl = str_replace("%{$key}%", $val, $tpl); [$subject, $message] = explode("\r\n\r\n", $tpl, 2); return compact('subject', 'message'); } }