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');
$mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR APPLICATIVE] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTexte($message);
$mail->setFrom('supportdev');
$mail->setBodyText($message);
$mail->setFromKey('supportdev');
$mail->addToKey('supportdev');
$mail->send();
$mail->execute();
}
// Log exception, if logger available
if ($log = $this->getLog()) {

View File

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

View File

@ -769,10 +769,10 @@ class PiecesController extends Zend_Controller_Action
$privilegesLog = join('-', $privileges);
$mail = new Scores_Mail_Method();
$mail->setFrom('contact');
$mail->setFromKey('contact');
$mail->addToKey('support');
$mail->setSubject('[COMMANDE PIECES] - PRIVILEGES par email');
$mail->setBodyTexte(
$mail->setBodyText(
'COMMANDE DE PRIVILEGES - par email<br/>'.EOL.
'Demande pour recevoir ('.$privilegesJ.') pour SIREN : '.
'<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.
'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.';
$ws = new WsScores();

View File

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

View File

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

View File

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

View File

@ -1,14 +1,12 @@
<?php
class Scores_Mail_Method
class Scores_Mail_Method extends Zend_Mail
{
protected $config;
protected $mail;
protected $transport;
/**
* 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
* Si method = smtp
* (host => IP, dns)
@ -20,10 +18,14 @@ class Scores_Mail_Method
*/
public function __construct( $config = null )
{
$c = Zend_Registry::get('config');
$this->config = $c->profil->mail;
if ($config === null) {
$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
if ( $this->config->method == 'smtp' ) {
@ -54,7 +56,7 @@ class Scores_Mail_Method
// --- Configuration transport 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;
@ -64,19 +66,10 @@ class Scores_Mail_Method
* Champ From en fonction de la clé de configuration
* @param string $configKey
*/
public function setFrom($configKey)
public function setFromKey($configKey)
{
$email = $this->config->email->$configKey;
$this->mail->setFrom($email, ucfirst($configKey));
}
/**
* Set Reply-To address
* @param string $email
*/
public function setReplyTo($email)
{
$this->mail->setReplyTo($email);
$email = $this->config->email->$configKey;
$this->setFrom($email, ucfirst($configKey));
}
/**
@ -86,56 +79,47 @@ class Scores_Mail_Method
public function addToKey($configKey)
{
$email = $this->config->email->$configKey;
$this->mail->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));
$this->addTo($email, ucfirst($configKey));
}
/**
* Définit le sujet de l'email
* @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
* @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
* @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
*/
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.
protected function txtConvert($string) {
protected function txtConvert($string)
{
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
}
@ -143,5 +127,4 @@ class Scores_Mail_Method
{
return $transport->recipients . '_' . mt_rand() . '.tmp';
}
}

View File

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

View File

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

View File

@ -149,8 +149,8 @@ $emailTxt.= '<br/>';
//Envoi mail
$mail = new Scores_Mail_Method();
$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('supportdev@scores-decisions.com', 'SupportDev');
$mail->setBodyHtml($emailTxt);
$mail->send();
$mail->execute();

View File

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