113 lines
2.4 KiB
PHP
113 lines
2.4 KiB
PHP
<?php
|
|
class Mail
|
|
{
|
|
protected $config;
|
|
protected $mail;
|
|
|
|
/**
|
|
* Gestion de l'envoi des mails en fonction de la configuration
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$c = Zend_Registry::get('config');
|
|
$this->config = $c->profil->mail;
|
|
|
|
$this->mail = new Zend_Mail();
|
|
|
|
if ($this->config->method == 'smtp') {
|
|
$tr = new Zend_Mail_Transport_Smtp($this->config->smtp_host);
|
|
$this->mail->setDefaultTransport($tr);
|
|
} elseif ($this->config->method == 'smtpauth') {
|
|
$cnfg = array(
|
|
'auth' => 'login',
|
|
'username' => $this->config->username,
|
|
'password' => $this->config->password
|
|
);
|
|
$tr = new Zend_Mail_Transport_Smtp($this->config->smtp_host, $cnfg);
|
|
$this->mail->setDefaultTransport($tr);
|
|
} else {
|
|
$tr = new Zend_Mail_Transport_Sendmail();
|
|
$this->mail->setDefaultTransport($tr);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Champ From en fonction de la clé de configuration
|
|
* @param string $configKey
|
|
*/
|
|
public function setFrom($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);
|
|
}
|
|
|
|
/**
|
|
* Champ To en fonction de la clé de configuration
|
|
* @param string $configKey
|
|
*/
|
|
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 $nom
|
|
*/
|
|
public function addTo($email, $nom = '')
|
|
{
|
|
$this->mail->addTo($email, $this->txtConvert($nom));
|
|
}
|
|
|
|
/**
|
|
* Définit le sujet de l'email
|
|
* @param string $texte
|
|
*/
|
|
public function setSubject($texte = '')
|
|
{
|
|
$this->mail->setSubject($this->txtConvert($texte));
|
|
}
|
|
|
|
/**
|
|
* Définit le corps de l'email au format texte
|
|
* @param string $texte
|
|
*/
|
|
public function setBodyTexte($texte = '')
|
|
{
|
|
$this->mail->setBodyText($this->txtConvert($texte));
|
|
}
|
|
|
|
/**
|
|
* Définit le corps de l'email au format html
|
|
* @param string $html
|
|
*/
|
|
public function setBodyHtml($html = '')
|
|
{
|
|
$this->mail->setBodyHtml($this->txtConvert($html));
|
|
}
|
|
|
|
/**
|
|
* Envoi de l'emai
|
|
*/
|
|
public function send()
|
|
{
|
|
return $this->mail->send();
|
|
}
|
|
|
|
//We suppose that character encoding of strings is UTF-8 on PHP script.
|
|
protected function txtConvert($string) {
|
|
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
|
|
}
|
|
|
|
} |