/**
  * The index method is the default method called when you access this controller, so we can use this
  * to run the scheduled tasks. Takes an optional URL parameter "tasks", which is a comma separated list of
  * the module names to schedule, plus can contain "notifications" to fire the built in notifications system or
  * "all_modules" to fire every module that declares a scheduled task plugin.
  * If tasks are not specified then everything is run.
  */
 public function index()
 {
     $tm = microtime(true);
     $this->db = new Database();
     $system = new System_Model();
     if (isset($_GET['tasks'])) {
         $tasks = explode(',', $_GET['tasks']);
     } else {
         $tasks = array('notifications', 'all_modules');
     }
     // grab the time before we start, so there is no chance of a record coming in while we run that is missed.
     $currentTime = time();
     if (in_array('notifications', $tasks)) {
         $this->last_run_date = $system->getLastScheduledTaskCheck();
         $this->checkTriggers();
     }
     $tmtask = microtime(true) - $tm;
     if ($tmtask > 5) {
         self::msg("Triggers & notifications scheduled task took {$tmtask} seconds.", 'alert');
     }
     $this->runScheduledPlugins($system, $tasks);
     if (in_array('notifications', $tasks)) {
         $swift = email::connect();
         $this->doRecordOwnerNotifications($swift);
         $this->doDigestNotifications($swift);
     }
     // mark the time of the last scheduled task check, so we can get diffs next time
     $this->db->update('system', array('last_scheduled_task_check' => "'" . date('c', $currentTime) . "'"), array('id' => 1));
     self::msg("Ok!");
     $tm = microtime(true) - $tm;
     if ($tm > 30) {
         self::msg("Scheduled tasks for " . implode(', ', $tasks) . " took {$tm} seconds.", 'alert');
     }
 }
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name)
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $body, $html = TRUE)
 {
     // Connect to SwiftMailer
     email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = Swift_Message::newInstance()->setBody($body, $html)->setSubject($subject);
     if (is_string($to)) {
         // Single recipient
         $message->setTo(array($to));
     } elseif (is_array($to)) {
         //array('to', array('address' => 'name'))
         //array('to', 'address')
         foreach ($to as $method => $add) {
             switch (strtolower($method)) {
                 case 'bcc':
                     $message->setBcc($add);
                     break;
                 case 'cc':
                     $message->setCc($add);
                     break;
                     //Default method is to
                 //Default method is to
                 default:
                     $message->setTo($add);
                     break;
             }
         }
     }
     $message->setFrom($from);
     return email::$mail->send($message);
 }
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name), or an array of From, Reply-To, Return-Path names
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $message, $html = FALSE)
 {
     // Connect to SwiftMailer
     email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');
     if (is_string($to)) {
         // Single recipient
         $recipients = new Swift_Address($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         // Create a list of recipients
         $recipients = new Swift_RecipientList();
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'), TRUE)) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $recipients->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $recipients->{$method}($set);
             }
         }
     }
     if (is_array($from) and isset($from['from'])) {
         foreach (array('reply-to' => 'setReplyTo', 'return-path' => 'setReturnPath') as $key => $method) {
             if (isset($from[$key])) {
                 $address = is_array($from[$key]) ? $from[$key] + array(NULL, NULL) : array($from[$key], NULL);
                 $message->{$method}(new Swift_Address($address[0], $address[1]));
             }
         }
         $from = $from['from'];
     }
     if (is_string($from)) {
         // From without a name
         $from = new Swift_Address($from);
     } elseif (is_array($from)) {
         //  Make sure both indicies are set
         $from = $from + array(NULL, NULL);
         // From with a name
         $from = new Swift_Address($from[0], $from[1]);
     }
     return email::$mail->send($message, $recipients, $from);
 }
示例#4
0
文件: email.php 项目: anqh/anqh
 /**
  * Send an email message.
  *
  * @param   string|array  $to        recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  $from      sender email (and name)
  * @param   string        $subject   message subject
  * @param   string        $message   body
  * @param   boolean       $html      send email as HTML
  * @param   string|array  $reply_to  reply-to address (and name)
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $message, $html = false, $reply_to = null)
 {
     // Connect to SwiftMailer
     Email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
     if (is_string($to)) {
         // Single recipient
         $message->setTo($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'), true)) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $message->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $message->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $message->setFrom($from);
     } elseif (is_array($from)) {
         // From with a name
         $message->setFrom($from[0], $from[1]);
     }
     if (is_string($reply_to)) {
         // Reply to without a name
         $message->setReplyTo($reply_to);
     } elseif (is_array($reply_to)) {
         // Reply to with a name
         $message->setReplyTo($reply_to[0], $reply_to[1]);
     }
     return Email::$mail->send($message);
 }
示例#5
0
 private function send_email($email, $subject, $content)
 {
     $swift = email::connect();
     $from = '*****@*****.**';
     $subject = $subject;
     $message = $content;
     if (!IN_PRODUCTION) {
         echo $content;
     }
     $recipients = new Swift_RecipientList();
     $recipients->addTo($email);
     // Build the HTML message
     $message = new Swift_Message($subject, $message, "text/html");
     $succeeded = !!$swift->send($message, $recipients, $from);
     $swift->disconnect();
     return $succeeded;
 }
示例#6
0
文件: forgotpass.php 项目: vobinh/PHP
 private function send_email($result)
 {
     // Create new password for customer
     $new_pass = text::random('numeric', 8);
     if (isset($result->member_email) && !empty($result->member_email)) {
         $result->member_pw = md5($new_pass);
     }
     $result->save();
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     //$from = array($this->site['site_email'], 'Yesnotebook get password');
     $from = $this->site['site_email'];
     $subject = 'Your Temporary Password for ' . $this->site['site_name'];
     //HTML message
     //print_r($html_content);die();
     //Replate content
     $html_content = $this->Data_template_Model->get_value('EMAIL_FORGOTPASS');
     $name = $result->member_fname . ' ' . $result->member_lname;
     $html_content = str_replace('#name#', $name, $html_content);
     if (isset($result->member_email) && !empty($result->member_email)) {
         $html_content = str_replace('#username#', $result->member_email, $html_content);
     }
     $html_content = str_replace('#site#', substr(url::base(), 0, -1), $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#password#', $new_pass, $html_content);
     $html_content = str_replace('#EmailAddress#', $this->site['site_email'], $html_content);
     //fwrite($fi, $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     if (isset($result->member_email) && !empty($result->member_email)) {
         $recipients->addTo($result->member_email);
     }
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         //$this->session->set_flash('success_msg',Kohana::lang('errormsg_lang.info_mail_change_pass'));
         if (isset($result->member_email) && !empty($result->member_email)) {
             url::redirect(url::base() . 'forgotpass/thanks/' . $result->uid . '/customer');
         }
         die;
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
示例#7
0
文件: payment.php 项目: vobinh/PHP
 private function send_email($record, $member, $test)
 {
     $swift = email::connect();
     $from = $this->site['site_email'];
     $mailuser = $this->sess_cus['email'];
     $subject = 'Check Code ' . $this->site['site_name'];
     $html_content = $this->data_template_model->get_value('EMAIL_CHECKCODE_USER');
     $html_content = str_replace('#date#', date('m/y/Y', strtotime('now')), $html_content);
     $html_content = str_replace('#username#', $this->sess_cus['name'], $html_content);
     $html_content = str_replace('#test#', $test['test_title'], $html_content);
     $html_content = str_replace('#description#', $record['description'] != '' ? '<p><strong>Description: ' . $record['description'] . '</strong></p>' : '', $html_content);
     $html_content = str_replace('#period#', isset($list['start_date']) && $record['start_date'] != 0 ? date('m/d/Y', $record['start_date']) : '' . (isset($list['end_date']) && $record['end_date'] != 0) ? ' ~ ' . date('m/d/Y', $record['end_date']) : 'No limit', $html_content);
     $html_content = str_replace('#no#', isset($record['qty']) ? $record['usage_qty'] + 1 . '/' . $record['qty'] : 'No limit', $html_content);
     $recipients = new Swift_RecipientList();
     $recipients->addTo($this->site['site_email']);
     $recipients->addTo($mailuser);
     if (isset($record['email']) && $record['email'] != '') {
         $recipients->addTo($record['email']);
     }
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
示例#8
0
 public static function send($to, $from, $subject, $message, $html = false)
 {
     // Connect to SwiftMailer
     Email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === true ? 'text/html' : 'text/plain';
     // Create the message
     if (self::$view) {
         $template = self::$view;
     } else {
         $config = kohana::$config->load('email');
         $template = View::factory($config['template']);
         $template->set('message', $message);
     }
     $message .= $template->render();
     $message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
     if (is_string($to)) {
         // Single recipient
         $message->setTo($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'), true)) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $message->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $message->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $message->setFrom($from);
     } elseif (is_array($from)) {
         // From with a name
         $message->setFrom($from[0], $from[1]);
     }
     return Email::$mail->send($message);
 }
示例#9
0
文件: test.php 项目: vobinh/PHP
 private function send_email($record)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     $from = $this->site['site_email'];
     $subject = 'Testing ' . $this->site['site_name'];
     //HTML message
     $html_content = Data_template_Model::get_value('EMAIL_TESTING');
     //Replate content
     if (isset($this->sess_cus['name']) && !empty($this->sess_cus['name'])) {
         $name = $this->sess_cus['name'];
     } else {
         $name = $this->sess_cus['email'];
     }
     $html_content = str_replace('#name#', $name, $html_content);
     $test = $this->test_model->get($record['test_uid']);
     $html_content = str_replace('#test#', $test['test_title'], $html_content);
     $html_content = str_replace('#date#', $this->format_int_date($record['testing_date'], $this->site['site_short_date']), $html_content);
     $html_content = str_replace('#score#', $record['testing_score'], $html_content);
     $html_content = str_replace('#duration#', gmdate("H:i:s", $record['duration']), $html_content);
     $html_content = str_replace('#code#', $record['testing_code'], $html_content);
     $html_content = str_replace('#site#', $this->site['site_name'], $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($this->sess_cus['email']);
     //$recipients->addTo($this->site['site_email']);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
示例#10
0
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name)
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $message, $html = FALSE, $header = array())
 {
     // Connect to SwiftMailer
     Email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
     if (is_string($to)) {
         // Single recipient
         $message->setTo($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'))) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 // If set is something like a
                 // 'cc' => array( array(  '*****@*****.**', '*****@*****.**' => 'Person 2 Name', '*****@*****.**' ) );
                 if (count($set) == 1 && is_array($set[0])) {
                     foreach ($set[0] as $value) {
                         if (is_array($value)) {
                             // Add a recipient with name
                             $message->{$method}($value[0], $value[1]);
                         } else {
                             // Add a recipient without name
                             $message->{$method}($value);
                         }
                     }
                 } else {
                     $message->{$method}($set[0], $set[1]);
                 }
             } else {
                 // Add a recipient without name
                 $message->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $message->setFrom($from);
     } elseif (is_array($from)) {
         // From with a name
         $message->setFrom($from[0], $from[1]);
     }
     // Apply additional headers, like a List-Unsubscribe: <http://domain.com/member/unsubscribe/?listname=espc-tech@domain.com?id=12345N>
     // Header format is array('List-Unsubscribe'=>'<http://domain.com/member/unsubscribe/?listname=espc-tech@domain.com?id=12345N>')
     if (count($header)) {
         $headers = $message->getHeaders();
         foreach ($header as $name => $value) {
             $headers->addTextHeader($name, $value);
         }
     }
     return Email::$mail->send($message);
 }
示例#11
0
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name)
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send_multipart($to, $from, $subject, $plain = '', $html = '', $attachments = array())
 {
     // Connect to SwiftMailer
     email::$mail === NULL and email::connect();
     // Create the message
     $message = Swift_Message::newInstance($subject);
     // Add some "parts"
     switch (true) {
         case strlen($html) and strlen($plain):
             $message->setBody($html, 'text/html');
             $message->addPart($plain, 'text/plain');
             break;
         case strlen($html):
             $message->setBody($html, 'text/html');
             break;
         case strlen($plain):
             $message->setBody($plain, 'text/plain');
             break;
         default:
             $message->setBody('', 'text/plain');
     }
     if (!empty($attachments)) {
         foreach ($attachments as $file => $mime) {
             $filename = basename($file);
             // Use the Swift_File class
             $message->attach(Swift_Attachment::fromPath($file)->setFilename($filename));
         }
     }
     if (is_string($to)) {
         // Single recipient
         $recipients = $message->setTo($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'))) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $message->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $message->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $from = $message->setFrom($from);
     } elseif (is_array($from)) {
         // From with a name
         $from = $message->setFrom(array($from[0] => $from[1]));
     }
     return email::$mail->send($message);
 }
function send_out_user_email($db, $emailContent, $userId, $notificationIds, $email_config, $subscriptionSettingsPageUrl)
{
    $emailContent .= '<a href="' . $subscriptionSettingsPageUrl . '?user_id=' . $userId . '&warehouse_url=' . url::base() . '">Click here to update your subscription settings.</a><br/><br/>';
    $cc = null;
    $swift = email::connect();
    // Use a transaction to allow us to prevent the email sending and marking of notification as done
    // getting out of step
    try {
        //Get the user's email address from the people table
        $userResults = $db->select('people.email_address')->from('people')->join('users', 'users.person_id', 'people.id')->where('users.id', $userId)->limit(1)->get();
        $defaultEmailSubject = 'You have new notifications.';
        try {
            $emailSubject = kohana::config('notification_emails.email_subject');
            //Handle config file not present
        } catch (Exception $e) {
            $emailSubject = $defaultEmailSubject;
        }
        if (empty($emailSubject)) {
            $emailSubject = $defaultEmailSubject;
        }
        //When configured, add a link on the email to the notifications page
        try {
            $notificationsLinkUrl = kohana::config('notification_emails.notifications_page_url');
        } catch (exception $e) {
        }
        if (!empty($notificationsLinkUrl)) {
            try {
                $notificationsLinkText = kohana::config('notification_emails.notifications_page_url_text');
            } catch (exception $e) {
            }
            if (empty($notificationsLinkText)) {
                $notificationsLinkText = 'Click here to go your notifications page.';
            }
            $emailContent .= '<a href="' . $notificationsLinkUrl . '">' . $notificationsLinkText . '</a></br>';
        }
        $message = new Swift_Message($emailSubject, $emailContent, 'text/html');
        $recipients = new Swift_RecipientList();
        $recipients->addTo($userResults[0]->email_address);
        // send the email
        $swift->send($message, $recipients, $email_config['address']);
        kohana::log('info', 'Email notification sent to ' . $userResults[0]->email_address);
        //All notifications that have been sent out in an email are marked so we don't resend them
        $db->set('email_sent', 'true')->from('notifications')->in('id', $notificationIds)->update();
        //As Verifier Tasks, Pending Record Tasks need to be actioned, we don't auto acknowledge them
        $db->set('acknowledged', 't')->from('notifications')->where("source_type != 'VT' AND source_type != 'PT'")->in('id', $notificationIds)->update();
    } catch (Exception $e) {
        $db->rollback();
        throw $e;
    }
}
示例#13
0
文件: contact.php 项目: vobinh/PHP
 private function send_email($record)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     $from = $record['txt_email'];
     $subject = Kohana::lang('contact_lang.tt_page') . ' ' . $this->site['site_name'];
     //HTML message
     $html_content = Data_template_Model::get_value('EMAIL_CONTACT', $this->get_client_lang());
     //Replate content
     $record['txt_content'] = isset($record['txt_content']) ? str_replace(array("\r\n", "\r", "\n"), "<br/>", $record['txt_content']) : '';
     $html_content = str_replace('#contact_name#', $record['txt_name'], $html_content);
     $html_content = str_replace('#contact_phone#', $record['txt_phone'], $html_content);
     $html_content = str_replace('#contact_subject#', $record['txt_subject'], $html_content);
     $html_content = str_replace('#contact_content#', $record['txt_content'], $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($this->site['site_email']);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         url::redirect('contact/thanks');
         die;
     }
     //Disconnect
     $swift->disconnect();
 }
示例#14
0
 private function send_email($result)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     $pass_random = rand(1000, 9999);
     $from = $this->site['site_email'];
     $subject = Kohana::lang('login_lang.lbl_forgotpass') . ' ' . $this->site['site_name'];
     //HTML message
     $html_content = Data_template_Model::get_value('EMAIL_FORGOTPASS', $this->get_admin_lang());
     //Replate content
     $html_content = str_replace('#name#', $result->user_name, $html_content);
     $html_content = str_replace('#username#', $result->user_name, $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#password#', $pass_random, $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($result->user_email);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         $this->session->set_flash('success_msg', Kohana::lang('errormsg_lang.info_mail_change_pass'));
         $result->user_pass = md5($pass_random);
         $result->save();
     }
     //Disconnect
     $swift->disconnect();
 }
示例#15
0
 /**
  * Save the results of a configuration of emails form, unless the skip button was clicked
  * in which case the user is redirected to a page allowing them to confirm this.
  */
 public function config_email_save()
 {
     if (isset($_POST['skip'])) {
         url::redirect('setup_check/skip_email');
     } else {
         $source = dirname(dirname(__FILE__)) . '/config_files/_email.php';
         $dest = dirname(dirname(dirname(dirname(__FILE__)))) . "/application/config/email.php";
         try {
             unlink($dest);
         } catch (Exception $e) {
             // file doesn't exist?'
         }
         try {
             $_source_content = file_get_contents($source);
             // Now save the POST form values into the config file
             foreach ($_POST as $field => $value) {
                 $_source_content = str_replace("*{$field}*", $value, $_source_content);
             }
             file_put_contents($dest, $_source_content);
             // Test the email config
             $swift = email::connect();
             $message = new Swift_Message('Setup test', Kohana::lang('setup.test_email_title'), 'text/html');
             $recipients = new Swift_RecipientList();
             $recipients->addTo($_POST['test_email']);
             if ($swift->send($message, $recipients, $_POST['address']) == 1) {
                 $_source_content = str_replace("*test_result*", 'pass', $_source_content);
                 file_put_contents($dest, $_source_content);
                 url::redirect('setup_check');
             } else {
                 $this->error = Kohana::lang('setup.test_email_failed');
                 $this->config_email();
             }
         } catch (Exception $e) {
             // Swift mailer messages tend to have the error message as the last part, with each part colon separated.
             $msg = explode(':', $e->getMessage());
             $this->error = $msg[count($msg) - 1];
             kohana::log('error', $e->getMessage());
             $this->config_email();
         }
     }
 }
 public function send_from_user($id = null)
 {
     $email_config = Kohana::config('email');
     $this->template->title = 'Forgotten Password Email Request';
     $this->template->content = new View('login/login_message');
     $this->template->content->message = 'You are already logged in.<br />';
     $this->template->content->link_to_home = 'YES';
     $person = ORM::factory('person', $id);
     if (!$person->loaded) {
         $this->template->content->message = 'Invalid Person ID';
         return;
     }
     $user = ORM::factory('user', array('person_id' => $id));
     if (!$user->loaded) {
         $this->template->content->message = 'No user details have been set up for this Person';
         return;
     }
     if (!$this->check_can_login($user)) {
         return;
     }
     $link_code = $this->auth->hash_password($user->username);
     $user->__set('forgotten_password_key', $link_code);
     $user->save();
     try {
         $swift = email::connect();
         $message = new Swift_Message($email_config['forgotten_passwd_title'], View::factory('templates/forgotten_password_email_2')->set(array('server' => $email_config['server_name'], 'new_password_link' => '<a href="' . url::site() . 'new_password/email/' . $link_code . '">' . url::site() . 'new_password/email/' . $link_code . '</a>')), 'text/html');
         $recipients = new Swift_RecipientList();
         $recipients->addTo($person->email_address, $person->first_name . ' ' . $person->surname);
         $swift->send($message, $recipients, $email_config['address']);
     } catch (Swift_Exception $e) {
         kohana::log('error', "Error sending forgotten password: "******"Forgotten password sent to {$person->first_name} {$person->surname}");
     $this->session->set_flash('flash_info', "Forgotten password sent to {$person->first_name} {$person->surname}");
     url::redirect('user');
 }
示例#17
0
 function sendorder()
 {
     $check = Validate::factory($_POST)->label('fio', 'ФИО')->label('address', 'адрес')->label('phone', 'телефон')->label('email', 'EMail')->rule('fio', 'not_empty')->rule('address', 'not_empty')->rule('phone', 'not_empty')->rule('phone', 'phone')->rule('email', 'not_empty')->rule('email', 'email');
     if ($check->check()) {
         //$order = ORM::factory('good', $_POST['orderid'])->as_array();
         $session = Session::instance();
         $_SESSION =& $session->as_array();
         $orders = '<b>Наименования:</b><br>';
         $price = 0;
         foreach ($_SESSION['orders'] as $k => $v) {
             $orders .= $_SESSION['orders'][$k]['name'] . ' (ID: ' . $_SESSION['orders'][$k]['id'] . ') - ' . $_SESSION['orders'][$k]['price'] . ' грн. (' . $_SESSION['orders'][$k]['count'] . '&nbsp;' . $_SESSION['orders'][$k]['select'] . ')<br>';
             $cof = $_SESSION['orders'][$k]['select'] == 'kg' ? $_SESSION['orders'][$k]['count'] : $_SESSION['orders'][$k]['count'] / 1000;
             $price += $_SESSION['orders'][$k]['price'] * $cof;
         }
         $text = '<b>ФИО:</b>&nbsp;' . $_POST['fio'] . '<br>
                  <b>Адрес:</b>&nbsp;' . $_POST['address'] . '<br>
                  <b>Телефон:</b>&nbsp;' . $_POST['phone'] . '<br>
                  <b>EMail:</b>&nbsp;' . $_POST['email'] . '<br>' . $orders . '<p><b>Итоговая цена без доставки:</b> ' . $price;
         $mailer = email::connect();
         $message = Swift_Message::NewInstance('Новый заказ', $text, 'text/html', 'utf-8');
         $message->setTo('*****@*****.**');
         $message->setFrom('*****@*****.**');
         $mailer->send($message);
         Session::instance()->delete('orders');
         return TRUE;
     } else {
         return strtolower(implode(' и ', $check->errors('')));
     }
 }
示例#18
0
 private function send_email($record, $pass)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     $from = $this->site['site_email'];
     $subject = 'Register ' . $this->site['site_name'];
     //HTML message
     $html_content = Data_template_Model::get_value('EMAIL_REGISTER');
     $html_content = str_replace('#name#', $record['member_fname'] . ' ' . $record['member_lname'], $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#username#', $record['member_email'], $html_content);
     $html_content = str_replace('#password#', $pass, $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($record['member_email']);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
示例#19
0
文件: frm_bk.php 项目: vobinh/PHP
 private function send_email($result)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     //$from = array($this->site['site_email'], 'Yesnotebook get password');
     $str_random = rand(1000, 9999);
     $from = $this->site['site_email'];
     $subject = 'Forgot your password ' . $this->site['site_name'];
     //HTML message
     $path = 'application/views/email_tpl/forgotpass.tpl';
     $fi = fopen($path, 'r+');
     $html_content = file_get_contents($path);
     //Replate content
     $name = $result->admin_name;
     $html_content = str_replace('#first_name#', $name, $html_content);
     $html_content = str_replace('#username#', $result->admin_name, $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#password#', $str_random, $html_content);
     //fwrite($fi, $html_content);
     fclose($fi);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($result->admin_email);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         $this->session->set_flash('success_msg', Kohana::lang('errormsg_lang.msg_thanks_post'));
         $this->db->update('admin', array('admin_pass' => md5($str_random)), array('admin_email' => $result->admin_email));
         url::redirect('admin_login/forget_pass');
         die;
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
示例#20
0
 /**
  * Send an email message.
  *
  * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
  * @param   string|array  sender email (and name)
  * @param   string        message subject
  * @param   string        message body
  * @param   boolean       send email as HTML
  * @return  integer       number of emails sent
  */
 public static function send($to, $from, $subject, $message, $html = FALSE)
 {
     // Connect to SwiftMailer
     email::$mail === NULL and email::connect();
     // Determine the message type
     $html = $html === TRUE ? 'text/html' : 'text/plain';
     // Create the message
     $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');
     if (is_string($to)) {
         // Single recipient
         $recipients = new Swift_Address($to);
     } elseif (is_array($to)) {
         if (isset($to[0]) and isset($to[1])) {
             // Create To: address set
             $to = array('to' => $to);
         }
         // Create a list of recipients
         $recipients = new Swift_RecipientList();
         foreach ($to as $method => $set) {
             if (!in_array($method, array('to', 'cc', 'bcc'))) {
                 // Use To: by default
                 $method = 'to';
             }
             // Create method name
             $method = 'add' . ucfirst($method);
             if (is_array($set)) {
                 // Add a recipient with name
                 $recipients->{$method}($set[0], $set[1]);
             } else {
                 // Add a recipient without name
                 $recipients->{$method}($set);
             }
         }
     }
     if (is_string($from)) {
         // From without a name
         $from = new Swift_Address($from);
     } elseif (is_array($from)) {
         // From with a name
         $from = new Swift_Address($from[0], $from[1]);
     }
     return email::$mail->send($message, $recipients, $from);
 }
示例#21
0
 /**
  * Creates and stores a forgotten_password_key, then composes and sends an email to 
  * the user's registered address.
  *
  * @param   User_Model the user's User_Model
  * @param   Person_Model the user's Person_Model
  *
  * @return  void. Throws Kohana_User_Exception on error.
  */
 public function send_forgotten_password_mail($user, $person)
 {
     Kohana::log('debug', 'Entering Auth_Core->send_forgotten_password_mail');
     $email_config = Kohana::config('email');
     $link_code = $this->hash_password($user->username);
     $user->__set('forgotten_password_key', $link_code);
     $user->save();
     try {
         $swift = email::connect();
         $message = new Swift_Message($email_config['forgotten_passwd_title'], View::factory('templates/forgotten_password_email')->set(array('server' => $email_config['server_name'], 'new_password_link' => '<a href="' . url::site() . 'new_password/email/' . $link_code . '">' . url::site() . 'new_password/email/' . $link_code . '</a>')), 'text/html');
         $recipients = new Swift_RecipientList();
         $recipients->addTo($person->email_address, $person->first_name . ' ' . $person->surname);
         $swift->send($message, $recipients, $email_config['address']);
     } catch (Swift_Exception $e) {
         kohana::log('error', "Error sending forgotten password: "******"Forgotten password sent to {$person->first_name} {$person->surname}");
     return;
 }