1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| class core_model_mail{
/**
*
* Enter description here ...
* @var unknown_type
*/
protected $_mailer;
/**
*
* défini les options de transport
* @var $_transport_options
*/
protected $_transport_options = array(
'setHost'=>'localhost',
'setPort'=>25,
'setEncryption'=>false,
'setUsername'=>false,
'setPassword'=>false
);
/**
*
* Constructor
* @param string $type
* @param array $options
*/
public function __construct($type,$Options=null){
$this->_mailer = Swift_Mailer::newInstance(self::transportConfig($type,$Options));
}
/**
* Get options from the library
*
* @return array The currently set options
*/
private function getOptions() {
return $this->_transport_options;
}
/**
* INI transport
* @param string $type
* @param string $host
* @param integer $port
* @access public
* @static
*/
private function transportConfig($type='mail',$Options=null){
switch ($type){
case 'mail':
$config = Swift_MailTransport::newInstance();
break;
case 'smtp':
if($Options) {
if(!is_array($Options)) {
throw $this->newException('Options must be defined as an array!');
}
else {
$config = Swift_SmtpTransport::newInstance(
$Options['setHost'],
$Options['setPort'],
$Options['setEncryption']
)
->setUsername($Options['setUsername'])
->setPassword($Options['setPassword']);
}
}else{
$config = Swift_SmtpTransport::newInstance(self::getOptions());
}
break;
}
return $config;
}
} |
Partager