62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
|
<?php
|
||
|
class Mail
|
||
|
{
|
||
|
protected $config;
|
||
|
protected $mail = new Zend_Mail();
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'mail');
|
||
|
|
||
|
if ($this->config->method == 'smtp') {
|
||
|
$tr = new Zend_Mail_Transport_Smtp();
|
||
|
$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;
|
||
|
$mail->addTo($email, ucfirst($configKey));
|
||
|
}
|
||
|
|
||
|
public function addTo($email, $nom = '')
|
||
|
{
|
||
|
$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');
|
||
|
}
|
||
|
|
||
|
}
|