Example #1
0
 /**
  * Send e-mail to particular user.
  *
  * @access     public
  * @param      string $sSubject
  * @param      string $sBody
  * @return     bool
  * @since      3.5.0, 2015-02-17
  * @version    3.5.0, 2015-02-17
  */
 public function sendEmail($sSubject, $sBody)
 {
     if ($this->getEmail() !== NULL) {
         $oMail = new Mail();
         $oMail->setFrom(Config::get('base.email'));
         $oMail->setTo($this->getEmail());
         $oMail->setSubject($sSubject);
         $oMail->setBody($sBody, 'text/html');
         return Mailer::factory()->send($oMail);
     }
     return FALSE;
 }
Example #2
0
 /**
  * Send user account activation code.
  *
  * @access     public
  * @param      string    $sPassword
  * @param      UserModel $oUser
  * @return     bool
  * @throws     \Plethora\Exception
  * @throws     \Plethora\Exception\Fatal
  * @since      1.0.0
  * @version    2.1.0-dev
  */
 private function sendActivationCode($sPassword, UserModel $oUser)
 {
     $sUserAgent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
     $sActivationCode1 = mb_strlen($sPassword) * time() . $sUserAgent . $oUser->getLogin();
     $sActivationCode2 = sha1($sActivationCode1);
     $sActivationCode = base64_encode($sActivationCode2);
     $oActivationCode = new ActivationCodeModel();
     $oActivationCode->setUser($oUser);
     $oActivationCode->setCode($sActivationCode);
     DB::persist($oActivationCode);
     DB::flush();
     $sSubject = __(':appname - Activation link', ['appname' => Plethora\Core::getAppName()]);
     $mailContent = View::factory("user/frontend/register/message")->render(['sLogin' => $oUser->getLogin(), 'sActivationCode' => $sActivationCode]);
     $mailView = View::factory('base/email');
     $mailView->bind('sContent', $mailContent);
     $mailView->set('sTitle', $sSubject);
     $mail = $mailView->render();
     $oMessage = new Mail();
     $oMessage->setSubject($sSubject);
     $oMessage->setFrom(Config::get('base.email'));
     $oMessage->setTo($oUser->getEmail());
     $oMessage->setBody($mail, 'text/html');
     return Mailer::factory()->send($oMessage);
 }
Example #3
0
 /**
  * Queue a mail
  *
  * Save mail in file and send it when Mailer::sendQueue will be called
  *
  * @access   public
  * @param    Mail $oMessage
  * @return   boolean
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function queue(Mail $oMessage)
 {
     if ($oMessage->isComplete() === FALSE) {
         return FALSE;
     }
     $filesPath = Config::get('mailer.cache_path', FALSE);
     $serializedMail = serialize($oMessage);
     $fileName = $filesPath . 'mail_' . time() . '_' . md5($serializedMail) . '.txt';
     return file_put_contents($fileName, $serializedMail) ? TRUE : FALSE;
 }
Example #4
0
 /**
  * Send new message.
  *
  * @access   pubic
  * @param    Mail $oMessage
  * @return   bool
  * @throws   Exception
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function send(Mail $oMessage)
 {
     if (!$this->isConnected) {
         $this->connect();
         $this->authenticate();
     }
     foreach ($oMessage->getFrom() as $sVal) {
         $this->sendCommand('from', $sVal);
     }
     foreach ($oMessage->getTo() as $sVal) {
         $this->sendCommand('to', $sVal);
     }
     if (count($oMessage->getCC()) > 0) {
         foreach ($oMessage->getCC() as $sVal) {
             $this->sendCommand('to', $sVal);
         }
     }
     if (count($oMessage->getBcc()) > 0) {
         foreach ($oMessage->getBcc() as $sVal) {
             $this->sendCommand('to', $sVal);
         }
     }
     $this->sendCommand('data');
     $this->sendData($oMessage->getMessageHeaders() . preg_replace('/^\\./m', '..$1', $oMessage->getMessageBody()));
     $this->sendData('.');
     $sReply = $this->getData();
     if (strncmp($sReply, '250', 3) !== 0) {
         throw new Exception('Error with sending body');
     }
     return TRUE;
 }