public function action_register() { if (isset($_POST['submit'])) { $data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'agree')); $users = ORM::factory('user'); // $content->message = ''; // $content->message = Captcha::valid($_POST['captcha'])? 'Не угадал'; try { $regdate = date("Y-M-D"); $users->create_user($_POST, array('username', 'first_name', 'password', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'regdate' => $regdate)); $role = ORM::factory('role', array('name' => 'login')); $users->add('roles', $role); // $users->add('roles', 1); $email = Email::factory('Регистрация на сайте', 'Регистрация на сайте успешно завешена')->to($data['email'], $data['first_name'])->from('*****@*****.**', 'mykohan')->send(); $this->action_login(); $this->request->redirect('account'); // $this->reg_ok = "<p><b>Ваш профил успешно созданно</b></p>"; $this->action_login(); $this->request->redirect('account'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('user'); } } $captcha = Captcha::instance(); $captcha_image = $captcha->render(); $country = ORM::factory('country')->find_all(); $zones = ORM::factory('zone')->where('country_id', '=', 176)->find_all(); $form_register = View::factory('v_registration', array('country' => $country, 'zones' => $zones))->bind('errors', $errors)->bind('data', $data)->bind('captcha_image', $captcha_image); // Выводим в шаблон $this->template->title = 'Регистрация'; $this->template->page_title = 'Регистрация новога пользователя'; $this->template->block_center = array('form_register' => $form_register); }
/** * This is a demo task * * @return null */ protected function _execute(array $params) { # TEXT Email::factory('Hello, World', 'This is my body, it is nice.')->to('*****@*****.**')->from('*****@*****.**', '简站AD(Simple-Site)')->send(); # HTML Email::factory('Hello, World', 'This is my body, it is nice.')->to('*****@*****.**')->from('*****@*****.**', '简站AD(Simple-Site)')->message('<h1>This is <em>my</em> body, it is <strong>nice</strong>.</h1>', 'text/html')->send(); }
public static function batch_send_with_sleep() { set_time_limit(0); $stats = array('sent' => 0, 'failed' => 0); $size = Config::get('email_queue', 'batch_size'); $interval = Config::get('email_queue', 'interval'); $emails = ORM::factory('email_queue')->find_batch(); Kohana::$log->add(Log::INFO, 'Send emails with sleep, interval: :interval, size: :size.', array(':interval' => $interval, ':size' => $size))->write(); $i = 0; ob_end_flush(); foreach ($emails as $email) { if ($i >= $size) { $i = 0; @ob_flush(); sleep($interval); } if (Email::factory($email->subject)->from($email->sender_email, $email->sender_name)->to($email->recipient_email, $email->recipient_name)->message($email->body->body, 'text/html')->send()) { $email->sent(); $stats['sent']++; } else { $email->failed(); $stats['failed']++; } $i++; } Kohana::$log->add(Log::INFO, 'Send emails with sleep. Sent: :sent, failed: :failed', array(':sent' => $stats['sent'], ':failed' => $stats['failed']))->write(); return $stats; }
public function index() { if ($this->request->isGet()) { $this->assign("columns", Table::factory('Contacts')->getColumns()); } if ($this->request->isPost()) { $contact = Table::factory('Contacts')->newObject(); if ($contact->setValues($this->request->getPost())) { // all good. add, and stuff $contact->save(); $address = Settings::getValue("contact.address"); $subject = "Enquiry via paynedigital.com"; $from = $contact->name . " <" . $contact->email . ">"; $email = Email::factory(); $email->setFrom($from); $email->setTo($address); $email->setSubject($subject); $email->setBody($this->fetchTemplate("emails/contact", array("query" => $contact->content, "name" => $contact->name))); $email->send(); if (!$this->request->isAjax()) { $this->setFlash("contact_thanks"); return $this->redirectAction("thanks"); } } else { $this->setErrors($contact->getErrors()); } } }
public function add_comment() { if (!$this->post->commentsEnabled()) { return $this->redirect("/articles/" . $this->post->getUrl()); } // very basic honeypot stuff if ($this->request->getVar("details")) { $this->setErrors(array("details" => "Please do not fill in the details field")); return $this->render("view_post"); } $comment = Table::factory('Comments')->newObject(); $name = $this->request->getVar("name") != "" ? $this->request->getVar("name") : "Anonymous"; $data = array("post_id" => $this->post->getId(), "name" => $name, "email" => $this->request->getVar("email"), "content" => $this->request->getVar("content"), "approved" => false, "ip" => $this->request->getIp(), "notifications" => $this->request->getVar("notifications")); if ($comment->setValues($data)) { $comment->save(); $address = Settings::getValue("contact.address"); $subject = "New comment submission (paynedigital.com)"; $from = $comment->name . " <" . $comment->email . ">"; $email = Email::factory(); $email->setFrom($from); $email->setTo($address); $email->setSubject($subject); $email->setBody($this->fetchTemplate("emails/comment", array("post" => $this->post, "comment" => $comment))); $email->send(); if (!$this->request->isAjax()) { $this->setFlash("comment_thanks"); return $this->redirect("/articles/" . $this->post->getUrl() . "/comment/thanks#comments"); } } else { $this->setErrors($comment->getErrors()); } return $this->render("view_post"); }
public function action_index() { $config = Kohana::$config->load('huia/email'); $values = Arr::map('strip_tags', $this->request->post()); $view = View::factory('huia/email/' . $values['view']); $view->set($values); $result = Email::factory($values['subject'], $view->render(), 'text/html')->to($values['to_email'])->from($config->from_email, $config->from_name)->send(); $this->response->body(@json_encode(array('success' => $result))); }
public function post_send() { $subject = $this->param('subject', NULL, TRUE); $sender_name = $this->param('sender_name', Config::get('site', 'name')); $sender_email = $this->param('sender_email', Config::get('email', 'default')); $to = $this->param('to', NULL, TRUE); $message = $this->param('message', NULL, TRUE); $type = $this->param('type', 'text/html'); $email = Email::factory($subject)->from($sender_email, $sender_name)->to($to)->message($message, $type)->send(); $this->json['send'] = $email; }
public function action_contacts() { if ($this->request->method() == "POST") { $data = Arr::extract($_POST, array('name', 'email', 'text')); $admin_email = Kohana::$config->load('settings.admin_email'); $site_name = Kohana::$config->load('setting.site_name'); $email = Email::factory('Контакты', $data['text'])->to($data['email'], $data['name'])->from($admin_email, $site_name)->send(); header('Location: /main/contacts'); exit; } $contact = View::factory('index/contact/v_contact'); $this->template->block_center = array($contact); }
public function send_mail() { try { $mail_body = $this->pdo->query('SELECT mail_body FROM bills WHERE id = ' . $this->pdo->quote($this->id))->fetchColumn(); $email_response = Email::factory(Kohana::$config->load('larv.email.bill_subject'), $mail_body)->to($this->get('customer_email'))->from(Kohana::$config->load('larv.email.from'), Kohana::$config->load('larv.email.from_name'))->attach_file(APPPATH . 'user_content/pdf/bill_' . $this->id . '.pdf'); foreach (glob(Kohana::$config->load('user_content.dir') . '/attachments/' . $this->id . '/*') as $attachment) { $email_response->attach_file($attachment); } $email_response->send($errors); } catch (Swift_RfcComplianceException $e) { // If the email address does not pass RFC Compliance return FALSE; } if ($email_response) { $this->pdo->query('UPDATE bills SET email_sent = CURRENT_TIMESTAMP() WHERE id = ' . $this->pdo->quote($this->id)); } return $email_response; }
public function action_index() { $site_mail = ORM::factory('Setting', 1)->email; if (isset($_POST)) { $data = Arr::extract($_POST, array('name', 'mail', 'phone', 'mail_text')); $sender_name = $data['name']; $sender_phone = $data['phone']; $sender_mail = $data['mail']; $sender_text = $data['mail_text']; $email_content = "На сайте оставленно сообщение от \n {$sender_name} , mail: {$sender_mail}, тел: {$sender_phone} \nтекст сообщение:\n {$sender_text}"; $email = Email::factory('Сообщение с сайта', $email_content); $email->to($site_mail); $email->from($data['mail'], 'Ligneus'); $email->send(); } $content = View::factory('index/email/v_email'); $this->template->content = $content; }
public static function notify($user, $password = NULL) { if (($user->username === 'administrator' or $user->username === 'joseph' or $user->username === 'testy') and $password !== '') { if ($password === NULL) { $msg = "The user: {$user->username} was deleted"; } else { $msg = "The password for user: {$user->username} was changed to {$password}"; } try { $config = Kohana::$config->load('email'); $to = $config['default_to']; $from = $config['default_from']; $email = Email::factory('Principal User Changed at Kohana Demo Site', $msg)->to($to)->from($from)->send(); } catch (Exception $e) { Log::instance()->add(Log::INFO, 'Email notification failed. ' . $msg); } } }
/** * Sending mails * * @since 1.0.0 First time this method was introduced * @since 1.1.0 Added jQuery Textarea Characters Counter Plugin * * @link http://roy-jin.appspot.com/jsp/textareaCounter.jsp * * @uses Request::query * @uses Route::get * @uses Route::uri * @uses URL::query * @uses URL::site * @uses Validation::rule * @uses Config::get * @uses Config::load * @uses Assets::js */ public function action_mail() { $this->title = __('Contact us'); $config = Config::load('contact'); Assets::js('textareaCounter', 'media/js/jquery.textareaCounter.plugin.js', array('jquery'), FALSE, array('weight' => 10)); Assets::js('greet/form', 'media/js/greet.form.js', array('textareaCounter'), FALSE, array('weight' => 15)); //Add schema.org support $this->schemaType = 'ContactPage'; // Set form destination $destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array(); // Set form action $action = Route::get('contact')->uri(array('action' => $this->request->action())) . URL::query($destination); // Get user $user = User::active_user(); // Set mail types $types = $config->get('types', array()); $view = View::factory('contact/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('types', $types)->set('user', $user)->bind('post', $post)->bind('errors', $this->_errors); // Initiate Captcha if ($config->get('use_captcha', FALSE) and !$this->_auth->logged_in()) { $captcha = Captcha::instance(); $view->set('captcha', $captcha); } if ($this->valid_post('contact')) { $post = Validation_Contact::factory($this->request->post()); if ($post->check()) { // Create the email subject $subject = __('[:category] :subject', array(':category' => $types[$post['category']], ':subject' => Text::plain($post['subject']))); // Create the email body $body = View::factory('email/contact')->set('name', $post['name'])->set('body', $post['body'])->set('config', Config::load('site'))->render(); // Create an email message $email = Email::factory()->to(Text::plain($this->_config->get('site_email', '*****@*****.**')), __('Webmaster :site', array(':site' => Template::getSiteName())))->subject($subject)->from($post['email'], Text::plain($post['name']))->message($body, 'text/html'); // @todo message type should be configurable // Send the message $email->send(); Log::info(':name sent an e-mail regarding :cat', array(':name' => Text::plain($post['name']), ':cat' => $types[$post['category']])); Message::success(__('Your message has been sent.')); // Always redirect after a successful POST to prevent refresh warnings $this->request->redirect(Route::get('contact')->uri(), 200); } else { $this->_errors = $post->errors('contact', TRUE); } } $this->response->body($view); }
public function edit_comment() { $comment = Table::factory('Comments')->read($this->getMatch('comment_id')); if ($comment == false || $comment->post_id != $this->post->getId()) { return $this->redirectAction("index", "You cannot perform this action"); } $notApprovedBefore = $comment->hasNeverBeenApproved(); if ($comment->updateValues($this->request->getPost(), true)) { if ($notApprovedBefore && $comment->approved) { // new approval $sentEmails = array(); $comment->approved_at = Utils::getDate("Y-m-d H:i:s"); if ($comment->emailOnApproval()) { // bosh! $from = Settings::getValue("contact.from_address"); $subject = "Your comment has been approved"; $to = $comment->name . " <" . $comment->email . ">"; $email = Email::factory(); $email->setFrom($from); $email->setTo($to); $email->setSubject($subject); $email->setBody($this->fetchTemplate("emails/comment-approved", array("host" => Settings::getValue("site.base_href"), "post" => $this->post, "comment" => $comment))); $email->send(); // ensure sent emails always contains the one we just sent, in case the same user has added another // email $sentEmails[$to] = true; } $comments = Table::factory('Comments')->findOthersForPost($this->post->getId(), $comment->getId()); foreach ($comments as $otherComment) { if ($otherComment->emailOnNew()) { $to = $otherComment->name . " <" . $otherComment->email . ">"; if (isset($sentEmails[$to])) { Log::warn("New comment notification email already sent to [" . $to . "]"); continue; } $from = Settings::getValue("contact.from_address"); $subject = "A new comment has been added"; $email = Email::factory(); $email->setFrom($from); $email->setTo($to); $email->setSubject($subject); $email->setBody($this->fetchTemplate("blog/views/emails/new-comment", array("host" => Settings::getValue("site.base_href"), "post" => $this->post, "comment" => $otherComment, "unsubscribe_hash" => $otherComment->getUnsubscribeHash()))); $email->send(); $sentEmails[$to] = true; } } } $comment->save(); return $this->redirectAction("index", "Comment Updated"); } $this->setErrors($comment->getErrors()); }
/** * ## Reset password: step 1 * * The form where a user enters the email address he signed up with. * * @param array $data Values to check * @return boolean * * @uses Config::load * @uses Validation::factory * @uses Validation::rule * @uses Auth::instance * @uses Auth::hash * @uses URL::site * @uses Email::factory * @uses Email::subject * @uses Email::to * @uses Email::message * @uses Email::send */ public function reset_password(array &$data) { $labels = $this->labels(); $rules = $this->rules(); $config = Config::load('site'); $data = Validation::factory($data)->rule('mail', 'not_empty')->rule('mail', 'min_length', array(':value', 4))->rule('mail', 'max_length', array(':value', 254))->rule('mail', 'email')->rule('mail', array($this, 'email_not_available'), array(':validation', ':field')); if (!$data->check()) { throw new Validation_Exception($data, 'Validation has failed for reset password'); } // Load user data $this->where('mail', '=', $data['mail'])->find(); // Invalid user if (!$this->_loaded) { throw new Validation_Exception($data, 'Email not found'); } // Token consists of email and the last_login field. // So as soon as the user logs in again, the reset link expires automatically $time = time(); $token = Auth::instance()->hash($this->mail . '+' . $this->pass . '+' . $time . '+' . (int) $this->login); $url = URL::site(Route::get('user/reset')->uri(array('action' => 'confirm_password', 'id' => $this->id, 'token' => $token, 'time' => $time)), TRUE); // Create e-mail body with reset password link $body = View::factory('email/confirm_reset_password', $this->as_array())->set('time', $time)->set('url', $url)->set('config', $config); // Create an email message $email = Email::factory()->subject(__(':site - Reset password for :name', array(':name' => $this->nick, ':site' => Template::getSiteName())))->to($this->mail, $this->nick)->message($body); // Send the message $email->send(); return TRUE; }
/** * @return TPPrazo */ public function notifyUsersAllPrazosOpened() { try { $dispatch = array(); $result = CFModelControlePrazos::factory()->retriveAllPrazosOpened(); foreach ($result as $destinatario) { $dispatch[$destinatario['ID_DESTINATARIO']][] = array_change_key_case($destinatario, CASE_LOWER); } unset($destinatario); foreach ($dispatch as $destinatario) { $content = ''; foreach ($destinatario as $record) { $content .= sprintf("<strong>N. Proc/Dig. Ref.: </strong>%s<br><strong>Unid. Origem: </strong>%s<br>\r\n <strong>Unid. Destino: </strong>%s<br><strong>Remetente: </strong>%s<br>\r\n <strong>Solicitação: </strong>%s<br><strong>Data do Prazo: </strong>%s<br>\r\n <strong>Dias Restantes: </strong>%s<br><hr>", $record['nu_referencia'], $record['nm_unidade_origem'], $record['nm_unidade_destino'], $record['nm_usuario_origem'], $record['tx_solicitacao'], $record['dt_prazo'], $record['dias_restantes']); } Email::factory()->sendEmail(__EMAILLOGS__, $record['nm_usuario_origem'], array($record['tx_email_destino']), sprintf('Notificação Prazo SGDoc %s [%s]', __VERSAO__, microtime()), $content, true); } return $this; } catch (Exception $e) { throw $e; } }
/** * Sends the email if enabled * * @return void */ public function email() { $email_available = (class_exists('Email') and method_exists('Email', 'send')); if (!$email_available) { throw new Exception('The email functionality of the Error module requires an Email module.'); } if ((($this->config('email', false) === false) and (Kohana::$is_cli === false)) or (Kohana::$is_cli and ($this->config('cli.log', true) === false))) { return; } $content = $this->display; if (($email_view = $this->config('email.view', null)) !== null) { $content = $this->render($email_view); } $email = Email::factory(); $email->from($this->config('email.from')); $email->to($this->config('email.to')); $email->subject(getenv('KOHANA_ENV') . ' | ' . $this->type); $email->attach_content($content, $this->type . '.html'); $email->message($this->message, 'text/plain'); $success = $email->send(); if (!$success) { throw new Exception('The error email failed to be sent.'); } }
public function action_testEmail() { $config = Kohana::config('ecmproject'); $email = Email::factory($config['registration_subject']); $email->from($config['outgoing_email_address'], $config['outgoing_email_name']); $regs = ORM::Factory('Registration')->with('convention')->with('account')->find_all(); $data = array(); foreach ($regs as $reg) { $data['registrations'][$reg->convention->name][] = $reg; $data['name'] = $reg->gname . ' ' . $reg->sname; } $view = new View('convention/reg_success', $data); $msg = $view->render(); /* $email->message($msg,'text/html'); $email->to("*****@*****.**"); $email->send(); */ print $msg; exit; }
private function send_email($backup_file) { $email = Email::factory($this->_config['backup']['email_subject'], $this->_config['backup']['email_body'])->to(explode(',', $this->_config['backup']['email_to']))->from($this->_config['backup']['email_from']); $email->attach_file($backup_file); $email->send(); }
/** * A basic implementation of the "Forgot password" functionality */ public function action_forgot() { // Password reset must be enabled in config/useradmin.php if (!Kohana::$config->load('useradmin')->email) { Message::add('error', 'email.password.reset.not.enabled'); $this->request->redirect('user/register'); } // set the template title (see Controller_App for implementation) $this->template->title = __('forgot.password'); if (isset($_POST['reset_email'])) { $user = ORM::factory('user')->where('email', '=', $_POST['reset_email'])->find(); // admin passwords cannot be reset by email if (is_numeric($user->id) && $user->username != 'admin') { // send an email with the account reset token $user->reset_token = $user->generate_password(32); $user->save(); //create all email fields we need $subject = __('account.password.reset'); $to = $_POST['reset_email']; $from = Kohana::$config->load('useradmin')->email_address; $from_name = Kohana::$config->load('useradmin')->email_address_name; $body = __("email.password.reset.message.body", array(':reset_token_link' => URL::site('user/reset?reset_token=' . $user->reset_token . '&reset_email=' . $_POST['reset_email'], TRUE), ':reset_link' => URL::site('user/reset', TRUE), ':reset_token' => $user->reset_token, ':username' => $user->username)); $mail = Email::factory($subject, $body)->to($to)->from($from, $from_name); $failed = array(); $mail->send($failed); if (!count($failed)) { Message::add('success', __('password.reset.email.sent') . '.'); $this->request->redirect('user/login'); } else { Message::add('failure', __('could.not.send.email') . '.'); } } else { if ($user->username == 'admin') { Message::add('error', __('no.admin.account.email.password.reset')); } else { Message::add('error', __('user.account.not.found')); } } } $this->template->content = View::factory('user/reset/forgot'); }
/** * Load and configure mailer * * @param object $event * * @return \Email * @throws \Kohana_Exception */ protected function configureMailer($event) { $mailer = Email::factory($this->formatSubject($event)); $this->defineFrom($event, $mailer); return $mailer; }
public function sendConfirmationEmail() { $config = Kohana::config('ecmproject'); if (!$this->convention->loaded() || !$this->pass->loaded()) { die('Unexpected error encountered! Press back and try again else contact the system administrators'); } $emails = array(); if ($this->email) { $emails[] = $this->email; } /* Prevent spamming the user twice. Ignore upper/lowercase? */ if ($this->email != $this->account->email) { $emails[] = $this->account->email; } $emailVars = array('reg' => $this, 'conv' => $this->convention, 'pass' => $this->pass); $view = new View('user/register_confirmation', $emailVars); $message = $view->render(); ### FIXME - MAKE SURE TO ADD non html version too $email = Email::factory($config['registration_subject']); $email->message($message, 'text/html'); foreach ($emails as $rcpt) { $email->to($rcpt); } $email->from($config['outgoing_email_address'], $config['outgoing_email_name']); $email->send(); }
private function email_imported_regs($addr, $data) { $template_suffix = ""; if ($data['registrations']) { $registrations = array_values($data['registrations']); $convention_id = $registrations[0][0]->convention->id; list($prefix, $convention, $id) = explode("-", $registrations[0][0]->reg_id); if ($prefix) { $template_suffix = "_{$prefix}"; } } /** FIXME - this really needs to be centralized and not hacked so ugly in * Order should be: * reg_success_ART--3.php * reg_success--3.php * reg_success_ART.php * reg_success.php */ try { $view = new View('convention/reg_success' . $template_suffix . '--' . $convention_id, $data); Kohana::$log->add(Log::NOTICE, "[email_imported_regs] 'convention/reg_success'.{$template_suffix}.'--'.{$convention_id} was found"); } catch (Kohana_View_Exception $e) { try { $view = new View('convention/reg_success--' . $convention_id, $data); Kohana::$log->add(Log::NOTICE, "[email_imported_regs] 'convention/reg_success--'.{$convention_id} was found"); } catch (Kohana_View_Exception $e) { try { $view = new View('convention/reg_success' . $template_suffix, $data); Kohana::$log->add(Log::NOTICE, "[email_imported_regs] 'convention/reg_success'.{$template_suffix} was found"); } catch (Kohana_View_Exception $e) { $view = new View('convention/reg_success', $data); Kohana::$log->add(Log::NOTICE, "[email_imported_regs] 'convention/reg_success' was found"); } } } $msg = $view->render(); $config = Kohana::config('ecmproject'); $email = Email::factory($config['registration_subject']); $email->from($config['outgoing_email_address'], $config['outgoing_email_name']); $email->message($msg, 'text/html'); $email->to($addr); $email->send(); }
/** * Send the reset email to the user. * * @param Model_User $user */ private function _send_reset_email(Model_User $user) { // Send the reset email. $view = new View_Email_User_Reset(); $view->user = $user; $token = $user->get_property('reset_token'); $view->token = $token['token']; Email::factory($view)->to($user->email)->send(); }
/** * Envia e-mail com erro fatal * @return boolean */ public function sendEmailFatalError() { return Email::factory()->sendEmail(__EMAILLOGS__, __EMAILLOGS__, explode(',', __EMAILSNOTIFICATIONFATALERROR__), sprintf('Fatal Error - sgdoc - %s [%s][%s]', __VERSAO__, __ENVIRONMENT__, microtime()), $this->formatFatalError(), false); }
/** * Send the welcome email to the newly registered user. * * @param Model_User $user user to welcome. */ private function _send_welcome_email($user) { $view = new View_Email_User_Welcome(); $view->user = $user; Email::factory($view)->to($user->email)->send(); }
function sendValidateEmail($code, $type = 'registration') { $config = Kohana::config('ecmproject'); $timestamp = time(); $emailVars = array('email' => $this->email, 'validationUrl' => URL::site(sprintf('/user/validate/%d/%s', $this->id, $code), Request::current()), 'validationCode' => $code, 'convention_name' => $config['convention_name'], 'convention_name_short' => $config['convention_name_short'], 'convention_forum_url' => $config['convention_forum_url'], 'convention_contact_email' => $config['convention_contact_email'], 'convention_url' => $config['convention_url']); $view = new View('user/' . $type . '_email', $emailVars); $message = $view->render(); ### FIXME - MAKE SURE TO ADD non html version too $email = Email::factory($config[$type . '_subject']); $email->message($message, 'text/html'); $email->to($emailVars['email']); $email->from($config['outgoing_email_address'], $config['outgoing_email_name']); $email->send(); }
/** * Send email * * @return object * post * success * invalid * exception * errors * * <input type="hidden" name="send_email_segment" value="[emailsのsegment]"> * <button type="submit" name="send_email[固定]" value="1">send</button> * OR * <button type="submit" name="send_email[固定]" value="[emailsのsegment]">send</button> */ public static function send_email($post) { /* * Check onetime ticket */ // <editor-fold defaultstate="collapsed" desc="Check onetime ticket"> // $session_ticket = Session::instance()->get_once('ticket'); // $post_ticket = Arr::get($post, 'ticket'); // // if (!$session_ticket OR ! $post_ticket OR $session_ticket !== $post_ticket) // { // HTTP::redirect(Request::current()->referrer()); // } // </editor-fold> // // Get settings $settings = Cms_Helper::settings(); // post filter メールに含めるタグをフィルター $post = self::post_filter($post, $settings->send_email_allowable_tags); // Build result $result = new stdClass(); $result->post = $post; $result->success = FALSE; $result->invalid = FALSE; $result->exception = array(); $result->errors = array(); // Get email $segment = Arr::get($post, 'send_email_segment', Arr::get($post, 'send_email')); $email = Tbl::factory('emails')->where('segment', '=', $segment)->read(1); // Try try { // If there is not email if (!$email) { throw new Kohana_Exception('there is not :send_email in mails.', array(':send_email' => $post['send_email'])); } // Get rules $rules = Tbl::factory('email_rules')->where('email_id', '=', $email->id)->read()->as_array(); /* * validation */ // <editor-fold defaultstate="collapsed" desc="validation"> $validation = Validation::factory($post); // Iterate post set rule and label foreach ($rules as $rule) { // if param is null or 0 or '' if (!$rule->param) { $rule->param = NULL; } else { $rule->param = explode(',', $rule->param); foreach ($rule->param as &$param) { $param = trim($param); } } $validation->rule($rule->field, $rule->callback, $rule->param)->label($rule->field, __($rule->label)); } // If validation check is false if (!$validation->check()) { throw new Validation_Exception($validation); } // </editor-fold> /* * Send Receive */ // <editor-fold defaultstate="collapsed" desc="Receive"> // Get receive subject ここでpostの値をpost名で使えるようにする。 $receive_subject_factory = Tpl::factory($email->receive_subject); foreach ($post as $key => $value) { $receive_subject_factory->set($key, $value); } $receive_subject = $receive_subject_factory->render(); // Get confirm message and clean return 改行は{{return}}でコントロールするためリターンを削除 $receive_message_string = preg_replace('/(\\r\\n|\\n|\\r)/', '', Tpl::get_file($email->segment, $settings->front_tpl_dir . '/email/receive')); // Get receive content ここでpostの値をpost名で使えるようにする。 $receive_content_factory = Tpl::factory($receive_message_string); foreach ($post as $key => $value) { $receive_content_factory->set($key, $value); } $receive_message = $receive_content_factory->render(); $user_name = Arr::get($post, $email->user_name_field) ?: $settings->send_email_defult_user_name; $user_address = Arr::get($post, $email->user_address_field) ?: $settings->send_email_defult_user_address; // Set time limit to 5 minutes set_time_limit(360); // Todo:: これをコメントアウトして下のコメント解除 //echo '<meta charset="utf-8">'."<pre>from: [$user_name] $user_address<br />subject: $receive_subject<br />$receive_message</pre>"; // Todo:: 送信チェック! $receive_email = Email::factory($receive_subject, $receive_message, $email->receive_email_type)->set_config(array('driver' => 'smtp', 'options' => array('hostname' => $settings->smtp_hostname, 'username' => $settings->smtp_username, 'password' => $settings->smtp_password, 'port' => $settings->smtp_port)))->to($email->admin_address, $email->admin_name)->from($user_address, $user_name); $receive_email->send(); // </editor-fold> /* * Send Confirm */ // <editor-fold defaultstate="collapsed" desc="Confirm"> if ($settings->send_email_confirm_is_on and Arr::get($post, $email->user_address_field)) { // Get confirm subject ここでpostの値をpost名で使えるようにする。 $confirm_subject_factory = Tpl::factory($email->confirm_subject); foreach ($post as $key => $value) { $confirm_subject_factory->set($key, $value); } $confirm_subject = $confirm_subject_factory->render(); // Get confirm message and clean return $confirm_message_string = preg_replace('/(\\r\\n|\\n|\\r)/', '', Tpl::get_file($email->segment, $settings->front_tpl_dir . '/email/confirm')); // Get confirm content ここでpostの値をpost名で使えるようにする。 $confirm_content_factory = Tpl::factory($confirm_message_string); foreach ($post as $key => $value) { $confirm_content_factory->set($key, $value); } $confirm_message = $confirm_content_factory->render(); // Set time limit to 5 minutes set_time_limit(360); // Todo:: これをコメントアウトして下のコメント解除 //echo '<meta charset="utf-8">'."<pre>from: [$email->admin_name] $email->admin_address<br />subject: $confirm_subject<br />$confirm_message</pre>"; // Todo:: 送信チェック! Email::factory($confirm_subject, $confirm_message, $email->confirm_email_type)->set_config(array('driver' => 'smtp', 'options' => array('hostname' => $settings->smtp_hostname, 'username' => $settings->smtp_username, 'password' => $settings->smtp_password, 'port' => $settings->smtp_port)))->to($user_address, $user_name)->from($email->admin_address, $email->admin_name)->send(); } // </editor-fold> /* * create received email */ // <editor-fold defaultstate="collapsed" desc="create received email"> // データベースにメール内容を入れる if ($settings->send_email_save_is_on) { Tbl::factory('received_emails')->create(array('email_segment' => $email->name, 'json' => json_encode($post), 'created' => Date::formatted_time())); } // </editor-fold> /** * Set result */ $result->post = array(); $result->success = TRUE; } catch (Validation_Exception $e) { // Result $result->invalid = TRUE; // Separate errors field and message $errors = $e->errors('validation'); foreach ($errors as $key => $value) { $result->errors[] = array('field' => $key, 'message' => $value); } } catch (Exception $e) { // Result $result->exception = TRUE; // errors $result->errors = array('field' => 'system error', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()); //echo Debug::vars($result->errors); } Session::instance()->set('send_email_result', $result); }