New Mail Method

This commit is contained in:
Michael RICOIS 2015-06-11 15:29:14 +00:00
parent 98249c732b
commit 34a5d27545
11 changed files with 51 additions and 68 deletions

View File

@ -53,10 +53,10 @@ class ErrorController extends Zend_Controller_Action
$c = Zend_Registry::get('config'); $c = Zend_Registry::get('config');
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR APPLICATIVE] - '.$c->profil->server->name.' -'.date('Ymd')); $mail->setSubject('[ERREUR APPLICATIVE] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTexte($message); $mail->setBodyText($message);
$mail->setFrom('supportdev'); $mail->setFromKey('supportdev');
$mail->addToKey('supportdev'); $mail->addToKey('supportdev');
$mail->send(); $mail->execute();
} }
// Log exception, if logger available // Log exception, if logger available
if ($log = $this->getLog()) { if ($log = $this->getLog()) {

View File

@ -816,12 +816,12 @@ class EvaluationController extends Zend_Controller_Action
"<pre>".print_r($InfoEnq, 1)."</pre>"; "<pre>".print_r($InfoEnq, 1)."</pre>";
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('production'); $mail->setFromKey('production');
$mail->addToKey('support'); $mail->addToKey('support');
$mail->setSubject($sujet); $mail->setSubject($sujet);
$mail->setBodyHtml($texte); $mail->setBodyHtml($texte);
if ($mail->send()) { if ($mail->execute()) {
$commande = true; $commande = true;
} }
} }
@ -983,10 +983,10 @@ class EvaluationController extends Zend_Controller_Action
$texte = 'REQUEST='.EOL.print_r($request->getParams(),true).EOL. $texte = 'REQUEST='.EOL.print_r($request->getParams(),true).EOL.
'Utilisateur='.$login; 'Utilisateur='.$login;
$mail->setBodyTexte($texte); $mail->setBodyText($texte);
$mail->setFrom('contact'); $mail->setFromKey('contact');
$mail->addToKey('contact'); $mail->addToKey('contact');
$mail->send(); $mail->execute();
$c = Zend_Registry::get('config'); $c = Zend_Registry::get('config');
$path = $c->profil->path->data.'/log'; $path = $c->profil->path->data.'/log';

View File

@ -769,10 +769,10 @@ class PiecesController extends Zend_Controller_Action
$privilegesLog = join('-', $privileges); $privilegesLog = join('-', $privileges);
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('contact'); $mail->setFromKey('contact');
$mail->addToKey('support'); $mail->addToKey('support');
$mail->setSubject('[COMMANDE PIECES] - PRIVILEGES par email'); $mail->setSubject('[COMMANDE PIECES] - PRIVILEGES par email');
$mail->setBodyTexte( $mail->setBodyText(
'COMMANDE DE PRIVILEGES - par email<br/>'.EOL. 'COMMANDE DE PRIVILEGES - par email<br/>'.EOL.
'Demande pour recevoir ('.$privilegesJ.') pour SIREN : '. 'Demande pour recevoir ('.$privilegesJ.') pour SIREN : '.
'<a href="'.$this->view->url(array('controller'=>'identite', 'action'=>'fiche', 'siret'=> $this->siret), 'default', true).'">'. '<a href="'.$this->view->url(array('controller'=>'identite', 'action'=>'fiche', 'siret'=> $this->siret), 'default', true).'">'.
@ -780,7 +780,7 @@ class PiecesController extends Zend_Controller_Action
'pour login '.$user->getLogin().'('.$email.')<br/>'.EOL. 'pour login '.$user->getLogin().'('.$email.')<br/>'.EOL.
'Référence : '.$ref 'Référence : '.$ref
); );
$mail->send(); $mail->execute();
} }
$message = 'Votre commande a bien été prise en compte, vous recevrez ces documents sur votre e-mail.'; $message = 'Votre commande a bien été prise en compte, vous recevrez ces documents sur votre e-mail.';
$ws = new WsScores(); $ws = new WsScores();

View File

@ -306,11 +306,11 @@ class RechercheController extends Zend_Controller_Action
$objet = "Demande d'investigation"; $objet = "Demande d'investigation";
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('contact'); $mail->setFromKey('contact');
$mail->addToKey('support'); $mail->addToKey('support');
$mail->setSubject($objet); $mail->setSubject($objet);
$mail->setBodyHtml($message); $mail->setBodyHtml($message);
$mail->send(); $mail->execute();
} else { } else {
//Affichage formulaire //Affichage formulaire

View File

@ -697,11 +697,11 @@ class UserController extends Zend_Controller_Action
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setSubject("Demande d'envoi des identifiants"); $mail->setSubject("Demande d'envoi des identifiants");
$mail->setBodyHTML($mailbody); $mail->setBodyHTML($mailbody);
$mail->setFrom('support'); $mail->setFromKey('support');
$mail->addToKey('support'); $mail->addToKey('support');
$mail->setReplyTo($params['email']); $mail->setReplyTo($params['email']);
try { try {
$mail->send(); $mail->execute();
$this->view->assign('sendEmail' , true); $this->view->assign('sendEmail' , true);
} }
catch ( Zend_Mail_Transport_Exception $e ){ catch ( Zend_Mail_Transport_Exception $e ){

View File

@ -94,11 +94,11 @@ class Scores_Insee_AvisSituation
'pour login '.$user->getLogin().EOL; 'pour login '.$user->getLogin().EOL;
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('contact'); $mail->setFromKey('contact');
$mail->addToKey('support'); $mail->addToKey('support');
$mail->setSubject($objet); $mail->setSubject($objet);
$mail->setBodyText($texte); $mail->setBodyText($texte);
$mail->send(); $mail->execute();
} }
public function erreurmsg(){ public function erreurmsg(){

View File

@ -1,14 +1,12 @@
<?php <?php
class Scores_Mail_Method class Scores_Mail_Method extends Zend_Mail
{ {
protected $config; protected $config;
protected $mail;
protected $transport; protected $transport;
/** /**
* Gestion de l'envoi des mails en fonction de la configuration * Gestion de l'envoi des mails en fonction de la configuration
* Fournir un élément de configuration ou utiliser la configuration de l'application * Fournir un objet de configuration ou utiliser la configuration de l'application
*
* method => smtp, sendmail, file * method => smtp, sendmail, file
* Si method = smtp * Si method = smtp
* (host => IP, dns) * (host => IP, dns)
@ -20,10 +18,14 @@ class Scores_Mail_Method
*/ */
public function __construct( $config = null ) public function __construct( $config = null )
{ {
$c = Zend_Registry::get('config'); if ($config === null) {
$this->config = $c->profil->mail; $c = Zend_Registry::get('config');
$this->config = $c->profil->mail;
} else {
$this->config = $config;
}
$this->mail = new Zend_Mail(); $this->_charset = 'ISO-8859-15';
// --- Configuration du transport SMTP // --- Configuration du transport SMTP
if ( $this->config->method == 'smtp' ) { if ( $this->config->method == 'smtp' ) {
@ -54,7 +56,7 @@ class Scores_Mail_Method
// --- Configuration transport File // --- Configuration transport File
if ( $this->config->method == 'file' ) { if ( $this->config->method == 'file' ) {
$tr = new Zend_Mail_Transport_File(array('callback' => 'recipientFilename')); $tr = new Zend_Mail_Transport_File(array('callback' => array($this, 'recipientFilename')));
} }
$this->transport = $tr; $this->transport = $tr;
@ -64,19 +66,10 @@ class Scores_Mail_Method
* Champ From en fonction de la clé de configuration * Champ From en fonction de la clé de configuration
* @param string $configKey * @param string $configKey
*/ */
public function setFrom($configKey) public function setFromKey($configKey)
{ {
$email = $this->config->email->$configKey; $email = $this->config->email->$configKey;
$this->mail->setFrom($email, ucfirst($configKey)); $this->setFrom($email, ucfirst($configKey));
}
/**
* Set Reply-To address
* @param string $email
*/
public function setReplyTo($email)
{
$this->mail->setReplyTo($email);
} }
/** /**
@ -86,56 +79,47 @@ class Scores_Mail_Method
public function addToKey($configKey) public function addToKey($configKey)
{ {
$email = $this->config->email->$configKey; $email = $this->config->email->$configKey;
$this->mail->addTo($email, ucfirst($configKey)); $this->addTo($email, ucfirst($configKey));
}
/**
* Ajout d'un champ To en spécifiant l'email et le nom qui doit apparaitre
* @param string $email
* @param string $name
*/
public function addTo($email, $name = '')
{
$this->mail->addTo($email, $this->txtConvert($name));
} }
/** /**
* Définit le sujet de l'email * Définit le sujet de l'email
* @param string $texte * @param string $texte
*/ */
public function setSubject($texte = '') public function setSubjectC($texte = '')
{ {
$this->mail->setSubject($this->txtConvert($texte)); $this->setSubject($this->txtConvert($texte));
} }
/** /**
* Définit le corps de l'email au format texte * Définit le corps de l'email au format texte
* @param string $texte * @param string $texte
*/ */
public function setBodyTexte($texte = '') public function setBodyTextC($texte = '')
{ {
$this->mail->setBodyText($this->txtConvert($texte)); $this->setBodyText($this->txtConvert($texte));
} }
/** /**
* Définit le corps de l'email au format html * Définit le corps de l'email au format html
* @param string $html * @param string $html
*/ */
public function setBodyHtml($html = '') public function setBodyHtmlC($html = '')
{ {
$this->mail->setBodyHtml($this->txtConvert($html)); $this->setBodyHtml($this->txtConvert($html));
} }
/** /**
* Envoi de l'emai * Envoi de l'emai
*/ */
public function send() public function execute()
{ {
return $this->mail->send($this->transport); return $this->send($this->transport);
} }
//We suppose that character encoding of strings is UTF-8 on PHP script. //We suppose that character encoding of strings is UTF-8 on PHP script.
protected function txtConvert($string) { protected function txtConvert($string)
{
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8'); return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
} }
@ -143,5 +127,4 @@ class Scores_Mail_Method
{ {
return $transport->recipients . '_' . mt_rand() . '.tmp'; return $transport->recipients . '_' . mt_rand() . '.tmp';
} }
} }

View File

@ -3421,10 +3421,10 @@ class WsScores
$c = Zend_Registry::get('config'); $c = Zend_Registry::get('config');
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR SOAP] - '.$c->profil->server->name.' -'.date('Ymd')); $mail->setSubject('[ERREUR SOAP] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTexte($message); $mail->setBodyTextC($message);
$mail->setFrom('supportdev'); $mail->setFromKey('supportdev');
$mail->addToKey('supportdev'); $mail->addToKey('supportdev');
$mail->send(); $mail->execute();
} else { } else {
Zend_Registry::get('firebug')->info('Erreur SOAP - Code : '.$fault->faultcode.' - Message : '.$fault->faultstring); Zend_Registry::get('firebug')->info('Erreur SOAP - Code : '.$fault->faultcode.' - Message : '.$fault->faultstring);
} }

View File

@ -175,8 +175,8 @@ $emailTxt.= listeCmd(1);
//Envoi mail //Envoi mail
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('production'); $mail->setFromKey('production');
$mail->addTo('support@scores-decisions.com', 'Pieces'); $mail->addTo('support@scores-decisions.com', 'Pieces');
$mail->setSubject("[COMMANDES PIECES COURRIER] - ".date('d')."/".date('m')."/".date('Y')); $mail->setSubject("[COMMANDES PIECES COURRIER] - ".date('d')."/".date('m')."/".date('Y'));
$mail->setBodyHtml($emailTxt); $mail->setBodyHtml($emailTxt);
$mail->send(); $mail->execute();

View File

@ -149,8 +149,8 @@ $emailTxt.= '<br/>';
//Envoi mail //Envoi mail
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setSubject("[Commandes greffe non receptionné] - ".date('d')."/".date('m')."/".date('Y')); $mail->setSubject("[Commandes greffe non receptionné] - ".date('d')."/".date('m')."/".date('Y'));
$mail->setFrom('production'); $mail->setFromKey('production');
$mail->addTo('support@scores-decisions.com', 'Support'); $mail->addTo('support@scores-decisions.com', 'Support');
$mail->addTo('supportdev@scores-decisions.com', 'SupportDev'); $mail->addTo('supportdev@scores-decisions.com', 'SupportDev');
$mail->setBodyHtml($emailTxt); $mail->setBodyHtml($emailTxt);
$mail->send(); $mail->execute();

View File

@ -194,10 +194,10 @@ if ( isset($opts->rapport) || isset($opts->rapportcomplet) )
} }
//Envoi mail //Envoi mail
$mail = new Scores_Mail_Method(); $mail = new Scores_Mail_Method();
$mail->setFrom('production'); $mail->setFromKey('production');
$mail->addTo('support@scores-decisions.com', 'Support'); $mail->addTo('support@scores-decisions.com', 'Support');
$mail->addTo('supportdev@scores-decisions.com', 'Support Dev'); $mail->addTo('supportdev@scores-decisions.com', 'Support Dev');
$mail->setSubject($sujet); $mail->setSubject($sujet);
$mail->setBodyTexte($emailTxt); $mail->setBodyText($emailTxt);
$mail->send(); $mail->execute();
} }