/** * used to return the array that contains tempalte subject and template data * (body) of the required template * * @param string $templateName * @param string $sendTo * @param array $placeholderDetails * @return return array that contains template subject and data (body) on * success otherwise return array with faliure message */ public function templateMail($templateName = "Sign Up", $sendTo = "user", $placeholderDetails = array('#userName#' => 'abcd', '#email#' => '*****@*****.**')) { if (isset($templateName) && !empty($templateName)) { if (isset($sendTo) && !empty($sendTo)) { $templateTableObj = $this->getServiceLocator()->get('Manager\\Model\\TemplateTable'); $template = $templateTableObj->getTemplateByName($templateName); if ($template) { foreach ($placeholderDetails as $key => $value) { $template[1] = str_replace($key, $value, $template[1]); } } else { return array("message" => "template name provided does not exist"); } } else { return array("message" => "Please provide email at which you want to send the mail"); } } else { return array("message" => "Please Provide template name which you want to use"); } $replaceExtraPlaceHolder = CustomTemplateMail::getPalceHolderArray(); foreach ($replaceExtraPlaceHolder as $key => $value) { $template[1] = str_replace($key, $value, $template[1]); } return array('subject' => $template[0], 'body' => trim(html_entity_decode($template[1]))); }
/** * added for testing of custom class used send mails using tempalte engine */ public function templateMailAction() { $resultArray = CustomTemplateMail::templateMail($templateName = "Forget Password", $sendTo = "user", $placeholderDetails = array('#userName#' => 'abcd', '#email#' => '*****@*****.**')); print_r($resultArray); die; }