initial
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class RsvEmailSender {
|
||||
|
||||
private function headers(): array {
|
||||
return [
|
||||
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
|
||||
'Content-Type: text/html; charset=UTF-8',
|
||||
];
|
||||
}
|
||||
|
||||
private function do_send(string $to, string $subject, string $body): void {
|
||||
$success = wp_mail($to, $subject, $body, $this->headers());
|
||||
if (!$success) {
|
||||
throw new \RuntimeException('wp_mail failed for ' . $to);
|
||||
}
|
||||
}
|
||||
|
||||
public function send(string $to, string $subject, string $body): void {
|
||||
$this->do_send($to, $subject, $body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class RsvEmailTemplater {
|
||||
public function render(string $template, array $data) : string {
|
||||
return preg_replace_callback('/{{\s*(\w+)\s*}}/', function($matches) use ($data) {
|
||||
return $data[$matches[1]] ?? '';
|
||||
}, $template);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user