示例#1
0
 public function __construct($mailConfig)
 {
     SwiftMailer::getInstance();
     //Set mail config
     if (!is_array($mailConfig)) {
         throw new \Exception('mailConfig parameter must be an array');
     }
     // sender params
     if (!isset($mailConfig['fromEmail'])) {
         throw new \Exception('fromEmail parameter don\'t exists');
     }
     if (!Validate::isEmail($mailConfig['fromEmail'])) {
         throw new \Exception('fromEmail parameter must be a valid email');
     }
     $this->_mailConfig['fromEmail'] = $mailConfig['fromEmail'];
     if (!isset($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter don\'t exists');
     }
     if (!is_string($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter must be a string');
     }
     $this->_mailConfig['fromName'] = $mailConfig['fromName'];
     // receiver params
     if (!isset($mailConfig['toEmail'])) {
         throw new \Exception('toEmai parameter don\'t exists');
     }
     if (!Validate::isEmail($mailConfig['toEmail'])) {
         throw new \Exception('toEmail parameter must be a valid email');
     }
     $this->_mailConfig['toEmail'] = $mailConfig['toEmail'];
     if (!isset($mailConfig['toName'])) {
         throw new \Exception('toName parameter don\'t exists');
     }
     if (!is_string($mailConfig['fromName'])) {
         throw new \Exception('fromName parameter must be a string');
     }
     $this->_mailConfig['toName'] = $mailConfig['toName'];
     //Optional subject of mail params
     if (isset($mailConfig['mailSubject'])) {
         if (!is_string($mailConfig['mailSubject'])) {
             throw new \Exception('mailSubject parameter must be a string');
         }
         $this->_mailConfig['mailSubject'] = $mailConfig['mailSubject'];
     }
 }