loadTemplate($template); $this->subject=$this->inject($template["subject"],$cpts); $this->body=$this->inject($template["body"],$cpts); } public function send($destination){ $options=get_option( "visitors_edits_options", [ "admin_email"=>"", "notify_admin"=>null ]); $headers = "Content-Type: text/html; charset=UTF-8\r\n"; wp_mail($destination, $this->subject, $this->body, $headers); } private function loadTemplate($template){ ob_start(); require("mail_templates/".$template.".html"); $templateHtml=ob_get_clean(); preg_match("|(.*)|",$templateHtml,$subject); $templateHtml=preg_replace("|.*|","",$templateHtml); return [ "subject"=>$subject[1], "body"=>$templateHtml ]; } private function inject($str,$body){ foreach ($body as $key => $value) { $str=str_replace("#$key#",$value,$str); } return $str; } public function preview(){ echo $this->subject; echo $this->body; } } ?>