62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
class Mail
|
|
{
|
|
protected $config;
|
|
protected $mail;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', '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);
|
|
} else {
|
|
$tr = new Zend_Mail_Transport_Sendmail();
|
|
$this->mail->setDefaultTransport($tr);
|
|
}
|
|
}
|
|
|
|
public function setFrom($configKey)
|
|
{
|
|
$email = $this->config->$configKey;
|
|
$this->mail->setFrom($email, ucfirst($configKey));
|
|
}
|
|
|
|
public function addToKey($configKey)
|
|
{
|
|
$email = $this->config->$configKey;
|
|
$this->mail->addTo($email, ucfirst($configKey));
|
|
}
|
|
|
|
public function addTo($email, $nom = '')
|
|
{
|
|
$this->mail->addTo($email, $this->txtConvert($nom));
|
|
}
|
|
|
|
public function setSubject($texte = '')
|
|
{
|
|
$this->mail->setSubject($this->txtConvert($texte));
|
|
}
|
|
|
|
public function setBodyTexte($texte = '')
|
|
{
|
|
$this->mail->setBodyText($this->txtConvert($texte));
|
|
}
|
|
|
|
public function setBodyHtml($html = '')
|
|
{
|
|
$this->mail->setBodyHtml($this->txtConvert($html));
|
|
}
|
|
|
|
public function send()
|
|
{
|
|
$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');
|
|
}
|
|
|
|
} |