예제 #1
0
 /**
  * Send an e-mail to this user
  *
  * @param string $subjectTemplate A subject template in which {fields} are replaced
  * @param string $bbBodyTemplate A BB Code body template in which {fields} are replaced
  * @param boolean $useResetFields When true get a reset key for this user
  * @param string $locale Optional locale
  * @return mixed String or array of warnings when something went wrong
  */
 public function sendMail($subjectTemplate, $bbBodyTemplate, $useResetFields = false, $locale = null)
 {
     if ($useResetFields && !$this->canResetPassword()) {
         return $this->_('Trying to send a password reset to a user that cannot be reset.');
     }
     $mail = $this->loader->getMail();
     $mail->setTemplateStyle($this->getBaseOrganization()->getStyle());
     $mail->setFrom($this->getFrom());
     $mail->addTo($this->getEmailAddress(), $this->getFullName(), $this->project->getEmailBounce());
     if ($bcc = $this->project->getEmailBcc()) {
         $mail->addBcc($bcc);
     }
     if ($useResetFields) {
         $fields = $this->getResetPasswordMailFields($locale);
     } else {
         $fields = $this->getMailFields($locale);
     }
     // \MUtil_Echo::track($fields, $bbBodyTemplate);
     $fields = \MUtil_Ra::braceKeys($fields, '{', '}');
     $mail->setSubject(strtr($subjectTemplate, $fields));
     $mail->setBodyBBCode(strtr($bbBodyTemplate, $fields));
     try {
         $mail->send();
         return null;
     } catch (\Exception $e) {
         return array($this->_('Unable to send e-mail.'), $e->getMessage());
     }
 }