/** * Smarty {mailtemplate}{/mailtemplate} block plugin * * Type: block function<br> * @param array * <pre> * Params: name: string (name) * type: string - type of the mail * </pre> * @author Yackushev Denys * @param string contents of the block * @param Smarty clever simulation of a method * @return string string $content re-formatted */ function smarty_block_mailtemplate($params, $content, $smarty, &$repeat) { if (empty($params['name']) or empty($params['type'])) { throw new rad_exception('Not enouph actual params for {mailtemplate block!'); } $lang = !empty($params['lang']) ? $params['lang'] : null; rad_mailtemplate::setBlockContent($params['name'], $params['type'], $content, $lang); return ''; }
function _sendMail($email, $comment, $parent_comment, $link_to_comment) { $template_name = $this->config('comments.new_comment'); rad_mailtemplate::send($email, $template_name, array('comment' => $comment, 'parent_comment' => $parent_comment, 'link_to_comment' => $link_to_comment), $this->_mail_format); }
/** * Send the mail * @param string|array $to - mail reciver, can be also as array('*****@*****.**' => 'John Doe') * @param enum(html|text) $format - format of letter (html or text) * @return boolean */ public function send($to, $format = 'text') { //include_once LIBPATH rad_mailtemplate::setCurrentItem($this); $o = rad_rsmarty::getSmartyObject(); if ($this->getVars()) { foreach ($this->getVars() as $key => $value) { $o->assign($key, $value); } } if (!is_file(MAILTEMPLATESPATH . $this->getTemplateName())) { throw new rad_exception('File "' . MAILTEMPLATESPATH . $this->getTemplateName() . '" not found!'); } $o->fetch(MAILTEMPLATESPATH . $this->getTemplateName()); $o->clearAllAssign(); if (empty($this->_blocks[$format])) { throw new rad_exception('Format "' . $format . '" is not declared in file: "' . MAILTEMPLATESPATH . $this->getTemplateName() . '"'); } if (!empty($this->_mailer)) { $this->_mailer->setSubject($this->_blocks[$format]['subject']); if (!empty($this->_blocks[$format]['Cc'])) { $this->_mailer->setCc($this->_blocks[$format]['Cc']); } if (!empty($this->_blocks[$format]['Bcc'])) { $this->_mailer->setBcc($this->_blocks[$format]['Bcc']); } if (!empty($this->_blocks[$format]['headers'])) { $headers = rad_mailtemplate::parseHeader($this->_blocks[$format]['headers']); if (!empty($headers)) { foreach ($headers as $headerName => $headerValue) { switch (strtolower($headerName)) { case 'x-priority': $this->_mailer->setPriority((int) $headerValue); break; default: $this->_mailer->getHeaders()->addTextHeader($headerName, $headerValue); break; } } } } if (!empty($this->_blocks[$format]['body'])) { $this->_mailer->setBody($this->_blocks[$format]['body'], $format == 'text' ? 'text/plain' : 'text/html'); } if (!empty($this->_blocks[$format]['from'])) { $from = explode("\n", str_replace("\r", '', $this->_blocks[$format]['from'])); if (count($from)) { foreach ($from as $fromString) { $fromItem = explode('<', $fromString); if (count($fromItem) > 1) { $fromName = trim($fromItem[0]); $fromEmail = trim(str_replace('>', '', $fromItem[1])); } else { $fromName = trim($fromItem[0]); $fromEmail = trim($fromItem[0]); } $this->_mailer->setFrom(array($fromEmail => $fromName)); $this->_mailer->setReturnPath($fromEmail); } } } if (!empty($this->_blocks[$format]['transport'])) { $transport = explode("\n", str_replace("\r", '', $this->_blocks[$format]['transport'])); if (!empty($transport)) { $transportParams = array(); foreach ($transport as $transportKey => $transportString) { $transportString = trim($transportString); if (!empty($transportString)) { $transportItem = explode(':', $transportString); if (count($transportItem) > 1) { $transportItemKey = trim($transportItem[0]); unset($transportItem[0]); $transportItemValue = trim(implode(':', $transportItem)); $transportParams[$transportItemKey] = $transportItemValue; } } } } if (empty($transportParams['type'])) { throw new rad_exception('Error in mailtemplate "' . $this->getTemplateName() . '" at transport block: type of the transport required!'); } switch (strtolower($transportParams['type'])) { case 'smtp': if (empty($transportParams['host']) or empty($transportParams['port']) or empty($transportParams['user']) or !isset($transportParams['password'])) { throw new rad_exception('Error in mailtemplate "' . $this->getTemplateName() . '" at transport block: Not enouph actual params!'); } $this->_transportInstance = Swift_SmtpTransport::newInstance($transportParams['host'], $transportParams['port'])->setUsername($transportParams['user'])->setPassword($transportParams['password']); if (!empty($transportParams['security'])) { $this->_transportInstance->setEncryption($transportParams['security']); } break; case 'mail': $this->_transportInstance = Swift_MailTransport::newInstance(); break; default: throw new rad_exception('Error in mailtemplate "' . $this->getTemplateName() . '" Unknown transport type "' . $transportParams['type'] . '"!'); break; } //switch } $this->_mailer->setTo($to); $this->_mailer->setCharset('utf-8'); if (!$this->_transportInstance) { $this->_transportInstance = Swift_MailTransport::newInstance(); } return rad_mailtemplate::getMailer($this->_transportInstance)->send($this->_mailer); } else { $headers = 'MIME-Version: 1.0' . PHP_EOL; $headers .= 'Content-Transfer-Encoding: base64' . PHP_EOL; $headers .= 'From: ' . $this->_blocks[$format]['from'] . PHP_EOL; switch ($format) { case 'text': $headers = 'Content-Type: text/plain; charset=utf-8' . PHP_EOL; break; case 'html': $headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL; break; default: throw new rad_exception('Unknown format: "' . $format . '"'); break; } if (!empty($this->_blocks[$format]['Cc'])) { $headers .= 'Cc: ' . $this->_blocks[$format]['Cc'] . PHP_EOL; } if (!empty($this->_blocks[$format]['Bcc'])) { $headers .= 'Bcc: ' . $this->_blocks[$format]['Bcc'] . PHP_EOL; } if (!empty($this->_blocks[$format]['headers'])) { $headers .= $this->_blocks[$format]['headers']; } if (is_array($to)) { $toString = ''; foreach ($to as $toEmail => $toName) { $toString .= $toName . ' <' . $toEmail . '>,'; } $to = substr($toString, 0, strlen($toString) - 1); } return mail($to, $this->_blocks[$format]['subject'], chunk_split(base64_encode($this->_blocks[$format]['body'])), $headers); } }
/** * Register new user * @param struct_core_users $item */ public function register($item, $encode_password = true) { $item->u_active = 1; $item->u_subscribe_active = 1; $item->u_subscribe_langid = $this->getCurrentLangID(); $clearpass = empty($item->u_pass) ? rad_session::genereCode(6) : $item->u_pass; $item->u_pass = $encode_password ? rad_session::encodePassword($clearpass) : $clearpass; $this->insertItem($item); $item->u_id = $this->inserted_id(); rad_instances::get('model_coremail_subscribes')->removeExpired(); $item_url = new struct_coremail_subscribers_activationurl(); $item_url->sac_url = md5(rad_session::genereCode(31) . now() . $item->u_id); $item_url->sac_scrid = $item->u_id; $item_url->sac_type = 2; $item_url->email = $item->u_email; $item_url->date_created = time(); $item_url->save(); rad_mailtemplate::send($item->u_email, $this->config('registration.template'), array('user' => $item, 'link' => rad_input::makeURL('alias=register&c=' . urlencode($item_url->sac_url)), 'clearpass' => $clearpass), $this->config('mail_format', 'html')); }
function send() { if ($this->hash() == $this->request('hash')) { $req = $this->getAllRequest(); if ($this->_verifyInputData($req)) { $template = $req['FCKeditorMailBody']; $vars = array('%%SITE_URL%%' => 'SITE_URL'); $params = array('fromName' => $req['mailfromname'], 'fromEmail' => $req['mailfromemail'], 'Subject' => $req['mailsubject'], 'smtp' => '', 'format' => 'text/plain', 'header' => 'X-Priority: 1 (Higuest)'); if ($req['mailformat'] === '0') { $params['format'] = 'text/html'; } if (isset($req['mailsmtp']) and $req['mailsmtp'] === 'on') { $params['smtp'] = array('host' => $req['smtphost'], 'port' => (int) $req['smtpport'], 'user' => $req['smtpuser'], 'password' => $req['smtppass'], 'security' => ''); if ($req['smtpsecurity'] !== 'none') { $params['smtp']['security'] = $req['smtpsecurity']; } } $model = rad_instances::get('model_core_users'); $model->setState('select', 'count(*)'); $model->setState('u_group', array_values($req['mailgroups'])); $model->setState('u_subscribe_active', 1); $model->setState('u_subscribe_langid', (int) $this->getCurrentLangID()); $countUsers = $model->getItem(false); $model->unsetState('select'); for ($cnt = 0; $cnt < $countUsers; $cnt += $this->_mailperiteration) { $limit = $cnt . ',' . ($cnt + $this->_mailperiteration); $usersArr = NULL; $usersItems = $model->getItems($limit); if (count($usersItems)) { foreach ($usersItems as $user) { if (empty($user->u_fio)) { $usersArr[] = $user->u_email; } elseif (!empty($user->u_fio) and !empty($user->u_email)) { $usersArr[] = array($user->u_fio => $user->u_email); } else { continue; } } } if (count($usersArr)) { rad_mailtemplate::sendMasTemplate($usersArr, $template, $vars, $params); } else { $this->setVar('message', $this->lang('emailsnotfound.mail.error')); } } $this->setVar('message', '<span style="color:green">' . $this->lang('deliverycomplete.mail.text') . '</span>'); } $this->assignUserGroups(); } else { $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName()); } }
/** * @param struct_core_users $item */ private function sendActivationCode($item) { rad_instances::get('model_coremail_subscribes')->removeExpired(); $table = new model_core_table('subscribers_activationurl', 'coremail'); $table->setStates(array('sac_scrid' => $item->u_id, 'sac_type' => 2, 'email' => $item->u_email, 'date_confirmed' => 0)); $item_url = $table->getItem(); if ($item_url->sac_id) { if ($item_url->date_created + 300 > time()) { // wow, spam return; } $item_url->date_created = time(); $table->updateItem($item_url); } else { $item_url = new struct_coremail_subscribers_activationurl(); $item_url->sac_url = md5(rad_session::genereCode(31) . now() . $item->u_id); $item_url->sac_scrid = $item->u_id; $item_url->sac_type = 2; $item_url->email = $item->u_email; $item_url->date_created = time(); $table->insertItem($item_url); } rad_mailtemplate::send($item->u_email, $this->config('activate_email.template'), array('user' => $item, 'link' => $this->makeURL('alias=register&c=' . urlencode($item_url->sac_url)), 'clearpass' => ''), 'html'); }
/** * For item class to set itself * @param rad_mailtemplate_item $item */ public static function setCurrentItem(rad_mailtemplate_item $item) { self::$_item = $item; }
/** * Посылаем сообщение админу о новом заказе */ private function _sendMail(struct_corecatalog_orders $order, $type) { switch ($type) { case 'order_new': $template_name = $this->config('catalog.new_order'); break; case 'order_new_auth': $template_name = $this->config('catalog.new_auth_order'); break; default: $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName()); break; } $template_admin_name = $this->config('catalog.new_order_admin'); $email_to_user = $order->order_email; $email_to_admin = $this->config('admin.mail'); rad_mailtemplate::send($email_to_user, $template_name, array('order' => $order), $this->_mail_format); //mail to user rad_mailtemplate::send($email_to_admin, $template_admin_name, array('order' => $order), $this->_mail_admin_format); //copy to admin }
protected function _sendMail(struct_core_users $user, $type, $params = array()) { switch ($type) { case 'register_resend': case 'register': $template_name = $this->config('registration.template'); $link = $this->makeURL('c=' . urlencode($params['url'])); $email_to = $user->u_email; $clearpass = !empty($params['clearpass']) ? $params['clearpass'] : ''; break; case 'register_ok': $template_name = $this->config('registration.after_template'); $link = ''; $email_to = $user->u_email; $clearpass = ''; break; case 'send_admin': $template_name = $this->config('registration.admin_notify_template'); $link = ''; $email_to = 'admin'; $clearpass = !empty($params['clearpass']) ? $params['clearpass'] : ''; break; case 'remind': $template_name = $this->config('remind_password.template'); $link = $this->makeURL('actcode=' . urlencode($params['url'])); $email_to = $user->u_email; $clearpass = ''; break; case 'newpass': $template_name = $this->config('new_password.template'); $link = ''; $email_to = $user->u_email; $clearpass = !empty($params['clearpass']) ? $params['clearpass'] : ''; break; default: $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName()); break; } if ($email_to == 'admin') { $email_to = $this->config('admin.mail'); } rad_mailtemplate::send($email_to, $template_name, array('user' => $user, 'link' => $link, 'clearpass' => $clearpass), $this->_mail_format); }
/** * Просто отправляет мыло админу с инпут-полями */ function justSend() { if ($this->request('action') === 'send') { rad_mailtemplate::send($this->config('admin.mail'), $this->config('feedback.template'), array('email' => $this->request('sender_email'), 'fio' => $this->request('sender_fio'), 'message_body' => $this->request('message_body')), $this->_mail_format); } elseif ($this->request('action') == 'callback') { rad_mailtemplate::send($this->config('admin.mail'), $this->config('callback.template'), array('phone' => $this->request('phone'), 'fio' => $this->request('sender_fio')), $this->_mail_format); } }