wp-visitor-contributions/inc/mail.php

48 lines
1.2 KiB
PHP

<?php
class visitors_edits_EMAIL{
var $subject;
var $body;
public function __construct($cpts,$template){
$template=$this->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
]);
2016-07-12 16:58:19 -05:00
$headers= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
wp_mail($destination, $this->subject, $this->body,$headers);
/*
subject : $this->subject
body : $this->body
*/
}
private function loadTemplate($template){
ob_start();
require("mail_templates/".$template.".html");
$templateHtml=ob_get_clean();
preg_match("|<subject>(.*)</subject>|",$templateHtml,$subject);
$templateHtml=preg_replace("|<subject>.*</subject>|","",$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;
}
}
?>