예제 #1
0
파일: shortcuts.php 프로젝트: hung5s/yap
/**
 * Send email to an address
 *
 * @param string $email receiver's address
 * @param string $view path to view used by mailer (Yii's alias format)
 * @param array $data associative array passed to view
 */
function quickMail($email, $view, $data, $subject = 'Flexicore Member Registration Confirmation')
{
    Yii::import('Core.extensions.vendors.mail.YiiMailMessage');
    $viewName = end(explode('.', $view));
    Yii::app()->mail->viewPath = str_replace('.' . $viewName, '', $view);
    //send mail
    $message = new YiiMailMessage();
    $message->view = $viewName;
    $message->setSubject($subject);
    $message->setBody($data, 'text/html');
    $message->addTo($email);
    if (hasParam('Settings::ADMIN_EMAIL')) {
        $message->setFrom(array(Settings::ADMIN_EMAIL => Settings::SITE_NAME));
    }
    try {
        Yii::app()->mail->send($message);
    } catch (Exception $ex) {
        FErrorHandler::logError($ex->getMessage());
    }
}
예제 #2
0
파일: Email.php 프로젝트: hung5s/yap
 /**
  * Parse an email template and replace variables with values provided in params
  *
  * @param mixed $template relative template path, from resource/emails folder
  * @param mixed $params associative array of values to fill the template
  * @return mixed
  */
 public function parseTemplate()
 {
     $template = $this->template;
     $template = Yii::app()->assetManager->basePath . '/emailtemplates/' . $template . '.html';
     if (!file_exists($template) || ($body = file_get_contents($template)) === false) {
         FErrorHandler::logError('Cannot parse email template. The email template might not exist.');
         return NULL;
     }
     $body = preg_replace_callback('/\\{[\\w|-]*\\}/', array($this, 'replaceParams'), $body);
     return $body;
 }