_configs = new App_Service_ConfigManager();
$this->_ipManager = new App_Service_IpManager();
}
/**
* Invia un email all'utente con i parametri scelti
*
* @param String $message | $subject | $email
* @param boolean $text | $footer
* @return void
*/
public function direct($message, $subject, $email, $text = false, $footer = false)
{
$mail = new App_Model_Mail('UTF-8');
if ($footer) {
$message .= $this->addFooter();
}
$mail->setFrom($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'))->setSubject($subject)->addTo($email, 'Fatturab2b.net');
if ($text == false) {
$mail->setBodyHtml($message);
} else {
$mail->setBodyText($message);
}
$mail->send();
}
/**
* Invia un email all'utente in base a un template memorizzato nel DB.
* @param $email
* @param $template
* @param array $params
* @param null $filename
* @throws Zend_Mail_Exception
*/
public function sendEmailByTemplate($email, $template, $params = array(), $nomeMittente = null, $filename = null,$fileNameInterno = null)
{
$mail = new App_Model_Mail('UTF-8');
if(!$template){
throw new Exception("Email template non trovato impossibile inviare l'email");
}
$params = $this->preparaDatiPerSostituzione($params);
if (count($params) > 0) {
foreach ($params as $key => $val) {
$template['Oggetto'] = str_replace($key, $val, $template['Oggetto']);
$template['Testo'] = str_replace($key, $val, $template['Testo']);
}
}
if ($template['Footer'])
$template['Testo'] .= $this->addFooter();
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($this->_configs->get('email_mittente'), $nomeMittente)->setSubject($template['Oggetto']);
if ($template['Tipologia'] == 'HTML') {
$mail->setBodyHtml($template['Testo']);
} else if ($template['Tipologia'] == 'TEXT') {
$mail->setBodyText($template['Testo']);
}
//Nel caso in cui sono in test le email vengono inviate solo a sviluppoweb
if($this->_ipManager->controllaAbilitazioneTestSdk()){
$email=$this->_configs->get('test_email');
if($template['Resend'])
$template['Resend'] = 'TEST';
}
//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();
//INVIO COAPIA AL NOSTRO STISTEMA
if($template['Resend']){
$mail->clearRecipients();
//Controllo se devo reinviare la mail anche al nostro server
if ($template['Resend'] == 'INFO')
$mail->addTo($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'));
if ($template['Resend'] == 'ACQUISTI')
$mail->addTo($this->_configs->get('email_ordine'), $this->_configs->get('email_mittente_nome'));
if ($template['Resend'] == 'TEST')
$mail->addTo($this->_configs->get('test_email'), $this->_configs->get('email_mittente_nome'));
if($fileNameInterno){
$mail->setParts(array());
if (file_exists($fileNameInterno))
$mail->createAttachment(file_get_contents($fileNameInterno), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $fileNameInterno);
}
$mail->send();
//CANCELLO IL FILE DEL PDF
if ($fileNameInterno != null) {
if (file_exists($fileNameInterno))
@unlink($fileNameInterno);
}
}
//Invio l'email per la stampante con il testo vuoto
if ($template['Resend'] == 'ACQUISTI' && !$this->_ipManager->controllaAbilitazioneTestSdk()){
$mail->clearRecipients();
$mail->setBodyHtml("");
$mail->setBodyText("");
$mail->addTo("", $this->_configs->get('email_mittente_nome'));
$mail->send();
}
}
public function reportErrorToEmail($error, $shortdesc, Exception $e = null,$email = null)
{
$mail = new Zend_Mail('UTF-8');
if(!$email) $email = $this->_configs->get('test_email');
$subject = '--- SERVER Fatturab2b.net [EMAIL] --- ERRORE ---';
$message = '
ERROR-MESSAGE: ' . $shortdesc;
if ($e != null) {
$message .= '
STACK TRACE ERRORE:
';
foreach ($e->getTrace() as $key => $value) {
$message .= "
[ " . $key . "] = " . $value;
if (is_array($value)) {
$message .= '
[';
foreach ($value as $key2 => $value2) {
$message .= "[ " . $key2 . "] = " . $value2 . "
";
}
$message .= ']
';
}
}
$message .= '
EXCEPTION STAMP:
';
$message .= "
";
$message .= print_r($e,true);
$message .= "";
}
$message .= '";
$message .= print_r($error,true);
$message .= "";
$message .= '