public function output() { // TODO: Refactor into a content-type option if (\Director::is_ajax()) { return $this->friendlyErrorMessage; } else { // TODO: Refactor this into CMS if (class_exists('ErrorPage')) { $errorFilePath = \ErrorPage::get_filepath_for_errorcode($this->statusCode, class_exists('Translatable') ? \Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents($errorFilePath); if (!headers_sent()) { header('Content-Type: text/html'); } // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content); } } $renderer = \Debug::create_debug_view(); $output = $renderer->renderHeader(); $output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail); if (\Email::config()->admin_email) { $mailto = \Email::obfuscate(\Email::config()->admin_email); $output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . ''); } $output .= $renderer->renderFooter(); return $output; } }
public function onBeforeWrite() { if ($this->owner->BaseClass == "Discussion" && $this->owner->ID == 0) { $discussion = Discussion::get()->byID($this->owner->ParentID); $discussion_author = $discussion->Author(); $holder = $discussion->Parent(); $author = Member::get()->byID($this->owner->AuthorID); // Get our default email from address if (DiscussionHolder::config()->send_emails_from) { $from = DiscussionHolder::config()->send_email_from; } else { $from = Email::config()->admin_email; } // Vars for the emails $vars = array("Title" => $discussion->Title, "Author" => $author, "Comment" => $this->owner->Comment, 'Link' => Controller::join_links($holder->Link("view"), $discussion->ID, "#comments-holder")); // Send email to discussion owner if ($discussion_author && $discussion_author->Email && $discussion_author->RecieveCommentEmails && $discussion_author->ID != $this->owner->AuthorID) { $subject = _t("Discussions.NewCreatedReplySubject", "{Nickname} replied to your discussion", null, array("Nickname" => $author->Nickname)); $email = new Email($from, $discussion_author->Email, $subject); $email->setTemplate('NewCreatedReplyEmail'); $email->populateTemplate($vars); $email->send(); } // Send to anyone who liked this, if they want notifications foreach ($discussion->LikedBy() as $liked) { if ($liked->RecieveLikedReplyEmails && $liked->Email && $liked->ID != $author->ID) { $subject = _t("Discussions.NewLikedReplySubject", "{Nickname} replied to your liked discussion", null, array("Nickname" => $author->Nickname)); $email = new Email($from, $liked->Email, $subject); $email->setTemplate('NewLikedReplyEmail'); $email->populateTemplate($vars); $email->send(); } } } }
/** * returns the standard from email address (e.g. the shop admin email address) * @return String */ public static function get_from_email() { $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config(); if ($ecommerceConfig && $ecommerceConfig->ReceiptEmail) { return $ecommerceConfig->ReceiptEmail; } else { return Email::config()->admin_email; } }
/** * this is mainly a test harness * @return [type] [description] */ public function setupMailer() { Requirements::clear(); $this->parseVariables(true); if (empty($this->from)) { $this->from = Email::config()->admin_email; } $headers = $this->customHeaders; if (project()) { $headers['X-SilverStripeSite'] = project(); } $to = $this->to; $from = $this->from; $subject = $this->subject; if ($sendAllTo = $this->config()->send_all_emails_to) { $subject .= " [addressed to {$to}"; $to = $sendAllTo; if ($this->cc) { $subject .= ", cc to {$this->cc}"; } if ($this->bcc) { $subject .= ", bcc to {$this->bcc}"; } $subject .= ']'; unset($headers['Cc']); unset($headers['Bcc']); } else { if ($this->cc) { $headers['Cc'] = $this->cc; } if ($this->bcc) { $headers['Bcc'] = $this->bcc; } } if ($ccAllTo = $this->config()->cc_all_emails_to) { if (!empty($headers['Cc']) && trim($headers['Cc'])) { $headers['Cc'] .= ', ' . $ccAllTo; } else { $headers['Cc'] = $ccAllTo; } } if ($bccAllTo = $this->config()->bcc_all_emails_to) { if (!empty($headers['Bcc']) && trim($headers['Bcc'])) { $headers['Bcc'] .= ', ' . $bccAllTo; } else { $headers['Bcc'] = $bccAllTo; } } if ($sendAllfrom = $this->config()->send_all_emails_from) { if ($from) { $subject .= " [from {$from}]"; } $from = $sendAllfrom; } Requirements::restore(); return self::mailer()->setupMailer($to, $from, $subject, $this->attachments, $headers); }
/** * Return the list of members or emails to send comment notifications to * * @param Comment $comment * @return array|Traversable */ public function notificationRecipients($comment) { // Override this in your extending class to declare recipients $list = array(); if ($adminEmail = Email::config()->admin_email) { $list[] = $adminEmail; } $this->owner->extend('updateNotificationRecipients', $list, $comment); return $list; }
public function sendUpdateNotification() { $name = $data['FirstName'] . " " . $data['Surname']; $body = "{$name} has updated their details via the website. Here is the new information:<br/>"; foreach ($this->member->getAllFields() as $key => $field) { if (isset($data[$key])) { $body .= "<br/>{$key}: " . $data[$key]; $body .= $field != $data[$key] ? " <span style='color:red;'>(changed)</span>" : ""; } } $email = new Email(Email::config()->admin_email, Email::config()->admin_email, "Member details update: {$name}", $body); $email->send(); }
/** * Internal function designed to allow us to send a verification * email from multiple locations * * @param $member Member object to send email to * @return boolean */ protected function send_verification_email(Member $member) { if ($member) { $subject = _t("Users.PleaseVerify", "Please verify your account"); if (Users::config()->send_email_from) { $from = Users::config()->send_email_from; } else { $from = Email::config()->admin_email; } $body = $this->renderWith('UsersAccountVerification', array("Link" => Controller::join_links(Director::absoluteBaseURL(), $this->config()->url_segment, "verify", $member->ID, $member->VerificationCode))); $email = new Email($from, $member->Email, $subject, $body); $email->sendPlain(); return true; } return false; }
public function sendUpdateNotification($data) { $name = $data['FirstName'] . " " . $data['Surname']; $body = "{$name} has updated their details via the website. Here is the new information:<br/>"; $notifyOnFields = Member::config()->frontend_update_notification_fields ?: DataObject::database_fields('Member'); $changedFields = $this->member->getChangedFields(true, 2); $send = false; foreach ($changedFields as $key => $field) { if (in_array($key, $notifyOnFields)) { $body .= "<br/><strong>{$key}:</strong><br/>" . "<strike style='color:red;'>" . $field['before'] . "</strike><br/>" . "<span style='color:green;'>" . $field['after'] . "</span><br/>"; $send = true; } } if ($send) { $email = new Email(Email::config()->admin_email, Email::config()->admin_email, "Member details update: {$name}", $body); $email->send(); } }
/** * Like a particular discussion by ID * */ public function like() { $member = Member::currentUser(); $discussion = Discussion::get()->byID($this->request->param("ID")); if ($discussion && $discussion->canView($member)) { $this->setSessionMessage("message good", _t("Discussions.Liked", "Liked") . " '{$discussion->Title}'"); $member->LikedDiscussions()->add($discussion); $member->write(); $author = $discussion->Author(); // Send a notification (if the author wants it) if ($author && $author->RecieveLikedEmails && $author->Email && $member->ID != $author->ID) { if (DiscussionHolder::config()->send_email_from) { $from = DiscussionHolder::config()->send_email_from; } else { $from = Email::config()->admin_email; } $subject = _t("Discussions.LikedDiscussionSubject", "{Nickname} liked your discussion", null, array("Nickname" => $member->Nickname)); // Vars for the emails $vars = array("Title" => $discussion->Title, "Member" => $member, 'Link' => Controller::join_links($this->Link("view"), $discussion->ID, "#comments-holder")); $email = new Email($from, $author->Email, $subject); $email->setTemplate('LikedDiscussionEmail'); $email->populateTemplate($vars); $email->send(); } } return $this->redirect(Controller::join_links($this->Link("view"), $discussion->ID)); }
function run($request) { $update = array(); $orderStep = singleton("OrderStep"); $orderStep->requireDefaultRecords(); // ACCOUNT PAGE $accountPage = AccountPage::get()->First(); if (!$accountPage) { $accountPage = new AccountPage(); $accountPage->Title = 'Account'; $accountPage->MenuTitle = 'Account'; $accountPage->MetaTitle = 'Account'; $accountPage->Content = '<p>This is the account page. It is used for shop users to login and change their member details if they have an account.</p>'; $accountPage->URLSegment = 'account'; $accountPage->ShowInMenus = 0; $accountPage->writeToStage('Stage'); $accountPage->publish('Stage', 'Live'); DB::alteration_message('Account page \'Account\' created', 'created'); } else { DB::alteration_message('No need to create an account page, it already exists.'); } //CHECKOUT PAGE //CHECKOUT PAGE $checkoutPage = CheckoutPage::get()->First(); if (!$checkoutPage) { $checkoutPage = new CheckoutPage(); $checkoutPage->Content = '<p>This is the checkout page. You can edit all the messages in the Content Management System.</p>'; $checkoutPage->Title = 'Checkout'; $checkoutPage->TermsAndConditionsMessage = 'You must agree with the terms and conditions to proceed. '; $checkoutPage->MetaTitle = 'Checkout'; $checkoutPage->MenuTitle = 'Checkout'; $checkoutPage->URLSegment = 'checkout'; $update[] = 'Checkout page \'Checkout\' created'; $checkoutPage->ShowInMenus = 0; DB::alteration_message('new checkout page created.', 'created'); } else { DB::alteration_message('No need to create an checkout page, it already exists.'); } if ($checkoutPage) { if ($checkoutPage->TermsPageID == 0 && ($termsPage = Page::get()->Filter(array("URLSegment" => "terms-and-conditions"))->First())) { $checkoutPage->TermsPageID = $termsPage->ID; DB::alteration_message('terms and conditions page linked.', "created"); } else { DB::alteration_message('No terms and conditions page linked.'); } $checkoutPage->writeToStage('Stage'); $checkoutPage->publish('Stage', 'Live'); DB::alteration_message('Checkout page saved'); $orderConfirmationPage = OrderConfirmationPage::get()->First(); if ($orderConfirmationPage) { DB::alteration_message('No need to create an Order Confirmation Page. It already exists.'); } else { $orderConfirmationPage = new OrderConfirmationPage(); $orderConfirmationPage->ParentID = $checkoutPage->ID; $orderConfirmationPage->Title = 'Order confirmation'; $orderConfirmationPage->MenuTitle = 'Order confirmation'; $orderConfirmationPage->MetaTitle = 'Order confirmation'; $orderConfirmationPage->Content = '<p>This is the order confirmation page. It is used to confirm orders after they have been placed in the checkout page.</p>'; $orderConfirmationPage->URLSegment = 'order-confirmation'; $orderConfirmationPage->ShowInMenus = 0; $orderConfirmationPage->writeToStage('Stage'); $orderConfirmationPage->publish('Stage', 'Live'); DB::alteration_message('Order Confirmation created', 'created'); } } $update = array(); $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config(); if ($ecommerceConfig) { if (!$ecommerceConfig->ReceiptEmail) { $ecommerceConfig->ReceiptEmail = Email::config()->admin_email; if (!$ecommerceConfig->ReceiptEmail) { user_error("you must set an AdminEmail (Email::setAdminEmail)", E_USER_NOTICE); } $update[] = "created default entry for ReceiptEmail"; } if (!$ecommerceConfig->NumberOfProductsPerPage) { $ecommerceConfig->NumberOfProductsPerPage = 12; $update[] = "created default entry for NumberOfProductsPerPage"; } if (count($update)) { $ecommerceConfig->write(); DB::alteration_message($ecommerceConfig->ClassName . " created/updated: " . implode(" --- ", $update), 'created'); } } }
public function run($request) { $config = SiteConfig::current_site_config(); $default = Email::config()->admin_email; $default_config = $config->DefaultFromEmail; $member = Member::currentUser(); $to = $request->getVar('email'); $template = $request->getVar('template'); $disabled = $request->getVar('disabled'); if ($disabled) { MandrillMailer::setSendingDisabled(); } if ($default) { echo "Default email address is {$default}<br/>"; } else { echo "<div style='color:red'>Default email is not set. You should define one!</div>"; } if ($default_config) { echo "Default email set in siteconfig is {$default_config}<br/>"; } echo "The email will be sent to admin email, current member or an email passed in the url, like ?email=myemail@test.com<br/>"; echo "A default email is used by default. You can use a preset template by setting ?template=mytemplate<br/>"; echo "To prevent email from being sent, you can pass ?disabled=1<br/>"; echo '<hr/>'; if (!$default && $default_config) { $default = $default_config; } if (!$member && !$to) { if (!$default) { echo 'There are no recipient defined!'; exit; } else { $to = $default; } } if ($template) { $emailTemplate = EmailTemplate::getByCode($template); $email = $emailTemplate->getEmail(); $email->setSubject('Template ' . $template . ' from ' . $config->Title); $email->setSampleRequiredObjects(); } else { $email = new MandrillEmail(); $email->setSampleContent(); $email->setSubject('Sample email from ' . $config->Title); } if (!$to) { $email->setToMember($member); } else { $member = Member::get()->filter('Email', $to)->first(); if ($member) { $email->setToMember($member); } else { $email->setTo($to); } } echo 'Sending to ' . htmlentities($email->To()) . '<br/>'; echo 'Using theme : ' . $email->getTheme() . '<br/>'; echo '<hr/>'; $res = $email->send(); // Success! if ($res && is_array($res)) { echo '<div style="color:green">Successfully sent your email</div>'; echo 'Recipient : ' . $res[0] . '<br/>'; echo 'Additionnal headers : <br/>'; foreach ($res[3] as $k => $v) { echo "{$k} : {$v}" . '<br/>'; } echo 'Content : ' . $res[2]; } else { echo '<div style="color:red">Failed to send email</div>'; echo 'Error is : ' . MandrillMailer::getInstance()->getLastError(); } }
if (class_exists('DynamicCache')) { DynamicCache::config()->enabled = false; } // See where are included files Config::inst()->update('SSViewer', 'source_file_comments', true); // Fix this issue https://github.com/silverstripe/silverstripe-framework/issues/4146 if (isset($_GET['flush'])) { i18n::get_cache()->clean(Zend_Cache::CLEANING_MODE_ALL); } } else { // In production, sanitize php environment to avoid leaking information ini_set('display_errors', false); // Hide where are included files Config::inst()->update('SSViewer', 'source_file_comments', false); // Warn admin if errors occur SS_Log::add_writer(new SS_LogEmailWriter(Email::config()->admin_email), SS_Log::ERR, '<='); } // Protect website if env = isTest if (Director::isTest()) { // If php runs under cgi, Http auth might not work by default. Don't forget to update htaccess if (!isset($_SERVER['PHP_AUTH_USER'])) { if (isset($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION']) > 0) { list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); if (strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER['PHP_AUTH_PW']) == 0) { unset($_SERVER['PHP_AUTH_USER']); unset($_SERVER['PHP_AUTH_PW']); } } } BasicAuth::protect_entire_site(); }
/** * Provide content for the Preview tab * * @return \Tab */ protected function previewTab() { $tab = new Tab('Preview'); // Preview iframe $previewLink = '/admin/emails/EmailTemplate/PreviewEmail/?id=' . $this->ID; $iframe = new LiteralField('iframe', '<iframe src="' . $previewLink . '" style="width:800px;background:#fff;min-height:500px;vertical-align:top"></iframe>'); $tab->push($iframe); if (class_exists('CmsInlineFormAction')) { // Test emails $compo = new FieldGroup($recipient = new TextField('SendTestEmail', ''), $action = new CmsInlineFormAction('doSendTestEmail', 'Send')); $recipient->setAttribute('placeholder', '*****@*****.**'); $recipient->setValue(Email::config()->admin_email); $tab->push(new HiddenField('EmailTemplateID', '', $this->ID)); $tab->push(new HeaderField('SendTestEmailHeader', 'Send test email')); $tab->push($compo); } return $tab; }
/** * Send a message to the client containing the latest * note of {@link OrderStatusLog} and the current status. * * Used in {@link OrderReport}. * * @param string $note Optional note-content (instead of using the OrderStatusLog) */ public function sendStatusChange($title, $note = null) { if (!$note) { $latestLog = OrderStatusLog::get()->filter("OrderID", $this->order->ID)->filter("SentToCustomer", 1)->first(); if ($latestLog) { $note = $latestLog->Note; $title = $latestLog->Title; } } $member = $this->order->Member(); if (Config::inst()->get('OrderProcessor', 'receipt_email')) { $adminEmail = Config::inst()->get('OrderProcessor', 'receipt_email'); } else { $adminEmail = Email::config()->admin_email; } $e = new Order_statusEmail(); $e->populateTemplate(array("Order" => $this->order, "Member" => $member, "Note" => $note)); $e->setFrom($adminEmail); $e->setSubject($title); $e->setTo($member->Email); $e->send(); }
/** * Send to admin * * @return Email */ public function setToAdmin() { $email = Email::config()->admin_email; $sc = SiteConfig::current_site_config(); if ($sc->DefaultToEmail) { $email = $sc->DefaultToEmail; } elseif ($sc->ContactEmail) { $email = $sc->ContactEmail; } return $this->setTo($email); }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers * or "tech-speak". Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ public static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { // Ensure the error message complies with the HTTP 1.1 spec if (!$friendlyErrorMessage) { $friendlyErrorMessage = Config::inst()->get('Debug', 'friendly_error_header'); } $friendlyErrorMessage = strip_tags(str_replace(array("\n", "\r"), '', $friendlyErrorMessage)); if (!$friendlyErrorDetail) { $friendlyErrorDetail = Config::inst()->get('Debug', 'friendly_error_detail'); } if (!headers_sent()) { // Allow toggle between legacy behaviour and correctly setting HTTP response code // In 4.0 this should be fixed to always set this response code. if (Config::inst()->get('Debug', 'friendly_error_httpcode') || !Controller::has_curr()) { header($_SERVER['SERVER_PROTOCOL'] . " {$statusCode} {$friendlyErrorMessage}"); } } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { if (!headers_sent()) { header('Content-Type: text/html'); } if (class_exists('ErrorPage')) { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents($errorFilePath); // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content); } } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::config()->admin_email) { $mailto = Email::obfuscate(Email::config()->admin_email); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } return false; }
/** * Standard SS Method * @var Array */ public function populateDefaults() { parent::populateDefaults(); $this->ReceiptEmail = Email::config()->admin_email; }
/** * Resolve default send to address * @param string $to * @return string */ public static function resolveDefaultToEmail($to = null) { // In case of multiple recipients, do not validate anything if (is_array($to) || strpos($to, ',') !== false) { return $to; } $original_to = $to; if (!empty($to)) { $to = MandrillMailer::get_email_from_rfc_email($to); if (filter_var($to, FILTER_VALIDATE_EMAIL)) { return $original_to; } } $config = SiteConfig::current_site_config(); if (!empty($config->DefaultToEmail)) { return $config->DefaultToEmail; } if ($admin = Email::config()->admin_email) { return $admin; } return false; }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers * or "tech-speak". Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ public static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { if (!$friendlyErrorMessage) { $friendlyErrorMessage = Config::inst()->get('Debug', 'friendly_error_header'); } if (!$friendlyErrorDetail) { $friendlyErrorDetail = Config::inst()->get('Debug', 'friendly_error_detail'); } if (!headers_sent()) { $currController = Controller::has_curr() ? Controller::curr() : null; // Ensure the error message complies with the HTTP 1.1 spec $msg = strip_tags(str_replace(array("\n", "\r"), '', $friendlyErrorMessage)); if ($currController) { $response = $currController->getResponse(); $response->setStatusCode($statusCode, $msg); } else { header($_SERVER['SERVER_PROTOCOL'] . " {$statusCode} {$msg}"); } } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { if (class_exists('ErrorPage')) { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents(ASSETS_PATH . "/error-{$statusCode}.html"); // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content); } } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::config()->admin_email) { $mailto = Email::obfuscate(Email::config()->admin_email); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } return false; }
/** * * @param Float $amount * @param String $currency - e.g. NZD * @return String * */ protected function buildURL($amount, $currency) { $commsObject = new DpsPxPayComs(); /** * order details **/ $commsObject->setTxnType(DpsPxPayComs::get_txn_type()); $commsObject->setMerchantReference($this->ID); //replace any character that is NOT [0-9] or dot (.) $commsObject->setAmountInput(floatval(preg_replace("/[^0-9\\.]/", "", $amount))); $commsObject->setCurrencyInput($currency); /** * details of the redirection **/ $commsObject->setUrlFail(DpsPxPayPayment_Handler::absolute_complete_link()); $commsObject->setUrlSuccess(DpsPxPayPayment_Handler::absolute_complete_link()); /** * process payment data (check if it is OK and go forward if it is... **/ $url = $commsObject->startPaymentProcess(); $debugMessage = $commsObject->getDebugMessage(); $this->DebugMessage = $debugMessage; $this->write(); if ($this->config()->get("email_debug")) { $from = Email::config()->admin_email; $to = Email::config()->admin_email; $subject = "DPS Debug Information"; $body = $debugMessage; $email = new Email($from, $to, $subject, $body); $email->send(); } return $url; }
/** * Form action handler for CancelOrderForm. * * Take the order that this was to be change on, * and set the status that was requested from * the form request data. * * @param array $data The form request data submitted * @param Form $form The {@link Form} this was submitted on */ public function docancel($data, $form) { if (self::config()->allow_cancelling && $this->order->canCancel()) { $this->order->Status = 'MemberCancelled'; $this->order->write(); if (self::config()->email_notification) { $email = Email::create(Email::config()->admin_email, Email::config()->admin_email, sprintf(_t('Order.CANCELSUBJECT', 'Order #%d cancelled by member'), $this->order->ID), $this->order->renderWith('Order')); $email->send(); } $this->controller->sessionMessage(_t("OrderForm.ORDERCANCELLED", "Order sucessfully cancelled"), 'warning'); if (Member::currentUser() && ($link = $this->order->Link())) { $this->controller->redirect($link); } else { $this->controller->redirectBack(); } } }
public function getEmail($order = null) { $order = $order ?: $this->Order(); $email = Email::create(); $email->setTemplate($this->config()->email_template); if ($this->Send_To) { $email->setTo($this->Send_To); } elseif (trim($order->Name)) { $email->setTo($order->Name . ' <' . $order->LatestEmail . '>'); } else { $email->setTo($order->LatestEmail); } if ($this->Send_From) { $email->setFrom($this->Send_From); } else { if (\Config::inst()->get('OrderProcessor', 'receipt_email')) { $adminEmail = \Config::inst()->get('OrderProcessor', 'receipt_email'); } else { $adminEmail = \Email::config()->admin_email; } $email->setFrom($adminEmail); } $subject = $this->Send_Subject ? str_replace(['$Order.Reference', '$Order.ShippingAddress', '$Order.BillingAddress', '$Order.Customer.Name', '$Order.Total', '$Order.Items.count'], [$order->Reference, (string) $order->ShippingAddress(), (string) $order->BillingAddress(), $order->Customer() ? $order->Customer()->Name : 'Guest', $order->Total(), $order->Items()->count()], $this->Send_Subject) : _t('Order.RECEIPT_SUBJECT', 'Web Order - {reference}', ['reference' => $order->Reference]); $email->setSubject($subject); $note = $this->Send_Body ?: Object::create('BBCodeParser', $this->Note)->parse(); $email->populateTemplate(['Order' => $order, 'Member' => $order->Customer(), 'Note' => DBField::create_field('HTMLText', SSViewer::execute_string($note, $this, ['Order' => $order])), 'isPreview' => true]); $this->extend('updateEmail', $email); return $email; }
/** * Constructs an email object for the given order (if possible) * @param Order $order * @return Email|null */ public function getEmailForOrder(Order $order) { $data = CustomerDataExtractor::inst()->extract($order); $emailAddress = $data['Email']; // Send to admin? if ($this->To === self::TO_ADMIN) { $emailAddress = FollowUpEmail::config()->admin_email; if (empty($emailAddress)) { $emailAddress = Email::config()->admin_email; } } // Send the email if possible if (!empty($emailAddress)) { // fill in some additional templating $data = $this->performSubstitutions($data, $order); // build the email $email = new Email(); $email->setFrom(Email::config()->admin_email); $email->setTo($emailAddress); $email->setSubject($this->Subject); $body = $this->customise($data)->renderWith(array('FollowUpEmail')); foreach ($data as $k => $v) { $body = str_replace(array('http://{{{' . $k . '}}}', '{{{' . $k . '}}}'), array($v, $v), $body); } $email->setBody($body); return $email; } else { return null; } }
/** * @return string */ public function getFrom() { return Email::config()->admin_email; }
/** * Return the appropriate error content for the given status code * * @param int $statusCode * @return string Content in an appropriate format for the current request */ public function output($statusCode) { // TODO: Refactor into a content-type option if (\Director::is_ajax()) { return $this->getTitle(); } $renderer = \Debug::create_debug_view(); $output = $renderer->renderHeader(); $output .= $renderer->renderInfo("Website Error", $this->getTitle(), $this->getBody()); if (\Email::config()->admin_email) { $mailto = \Email::obfuscate(\Email::config()->admin_email); $output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . ''); } $output .= $renderer->renderFooter(); return $output; }
/** * @return string */ public static function DefaultEmailFrom() { $result = static::config()->default_email_from; if (!$result) { return Email::config()->admin_email; } return $result; }