コード例 #1
0
ファイル: email.php プロジェクト: Wildboard/WbWebApp
 /**
  * sends an email using content from model_content
  * @param  string $to        
  * @param  string $to_name   
  * @param  string $from      
  * @param  string $from_name 
  * @param  string $content   seotitle from Model_Content
  * @param  array $replace   key value to replace at subject and body
  * @param  array $file      file to attach to email
  * @return boolean            s
  */
 public static function content($to, $to_name = '', $from = NULL, $from_name = NULL, $content, $replace, $file = NULL)
 {
     $email = Model_Content::get($content, 'email');
     $ad_obj = new Model_Ad();
     //content found
     if ($email->loaded()) {
         if ($replace === NULL) {
             $replace = array();
         }
         if ($from === NULL) {
             $from = $email->from_email;
         }
         if ($from_name === NULL) {
             $from_name = core::config('general.site_name');
         }
         if (isset($file) and $ad_obj->is_valid_file($file)) {
             $file_upload = $file;
         } else {
             $file_upload = NULL;
         }
         //adding extra replaces
         $replace += array('[SITE.NAME]' => core::config('general.site_name'), '[SITE.URL]' => core::config('general.base_url'), '[USER.NAME]' => $to_name, '[USER.EMAIL]' => $to);
         //adding anchor tags to any [URL.* match
         foreach ($replace as $key => $value) {
             if (strpos($key, '[URL.') === 0 or $key == '[SITE.URL]') {
                 $replace[$key] = '[url=' . $value . ']' . $value . '[/url]';
             }
         }
         $subject = str_replace(array_keys($replace), array_values($replace), $email->title);
         $body = str_replace(array_keys($replace), array_values($replace), $email->description);
         return Email::send($to, $to_name, $subject, $body, $from, $from_name, $file_upload);
     } else {
         return FALSE;
     }
 }