Initial Commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
class App_Service_Emails
|
||||
{
|
||||
|
||||
const EMAIL_TEMPLATE_PATH = APPLICATION_PATH . "/../emailtemplate/";
|
||||
|
||||
protected $_configs;
|
||||
protected $_ipManager;
|
||||
protected $_genericModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->_configs = Zend_Registry::get('config');
|
||||
$this->_ipManager = new App_Service_IpManager();
|
||||
$this->_genericModel = new Application_Model_Generic();
|
||||
}
|
||||
|
||||
public function sendEmailByTemplateHtml($email, $oggetto, $templateName, $params = array(), $nomeMittente = null, $filename = null)
|
||||
{
|
||||
$mail = new App_Model_Mail('UTF-8');
|
||||
|
||||
$templateFileName = self::EMAIL_TEMPLATE_PATH.$templateName;
|
||||
|
||||
if(!file_exists($templateFileName)){
|
||||
throw new Exception("Email template non trovato impossibile inviare l'email");
|
||||
}
|
||||
|
||||
$testoEmail = file_get_contents($templateFileName);
|
||||
|
||||
$params = $this->preparaDatiPerSostituzione($params);
|
||||
|
||||
if (count($params) > 0) {
|
||||
foreach ($params as $key => $val) {
|
||||
$oggetto = str_replace($key, $val, $oggetto);
|
||||
$testoEmail = str_replace($key, $val, $testoEmail);
|
||||
}
|
||||
}
|
||||
|
||||
if ($filename != null) {
|
||||
if (file_exists($filename))
|
||||
$mail->createAttachment(file_get_contents($filename), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $filename);
|
||||
}
|
||||
|
||||
$nomeMittente = ($nomeMittente) ? $nomeMittente : $this->_configs->get('email_mittente_nome');
|
||||
|
||||
$mail->setFrom('noreply@fatturab2b.net', $nomeMittente)->setSubject($oggetto);
|
||||
|
||||
$mail->setBodyHtml($testoEmail);
|
||||
|
||||
//Inserisco il o i destinatari/o
|
||||
if (is_string($email)) {
|
||||
$mail->addTo($email, $email);
|
||||
} else if (is_array($email)) {
|
||||
foreach ($email as $val) {
|
||||
$mail->addTo($val);
|
||||
}
|
||||
}
|
||||
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Questa funzione presi i parametri passati nell array ne aggiunge i simboli
|
||||
* percentuale per farli riconoscere popi nel testo e sostituirli
|
||||
* @param $dati
|
||||
* @return array
|
||||
*/
|
||||
private function preparaDatiPerSostituzione($dati){
|
||||
$newParams = array();
|
||||
|
||||
foreach($dati as $key => $val){
|
||||
$newParams['%'.$key.'%'] = $val;
|
||||
}
|
||||
|
||||
return $newParams;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user