/** * Post user question * * @return void * @throws \Exception */ public function execute() { $post = $this->getRequest()->getPostValue(); if (!$post) { $this->_redirect('*/*/'); return; } $this->inlineTranslation->suspend(); try { $postObject = new \Magento\Framework\DataObject(); $postObject->setData($post); $error = false; if (!\Zend_Validate::is(trim($post['contact_email']), 'EmailAddress')) { $error = true; } if (!\Zend_Validate::is(trim($post['contact_question']), 'NotEmpty')) { $error = true; } if ($error) { throw new \Exception(); } $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['data' => $postObject])->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))->setReplyTo($post['contact_email'])->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); $this->messageManager->addSuccess(__('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')); $this->_redirect('delivery-charges'); return; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.')); $this->_redirect('delivery-charges'); return; } }
/** * Configure email template * * @return void */ protected function configureEmailTemplate() { $this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId()); $this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions()); $this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars()); $this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity()); }
public function sendNotification($data) { if (!$data) { return false; } $this->inlineTranslation->suspend(); try { $postObject = new \Magento\Framework\DataObject(); $postObject->setData($data); $error = false; $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; /* $from = [ 'name' => '', 'email' => '' ];*/ $email_template = $this->scopeConfig->getValue('cadou/email/template'); if (empty($email_template)) { $email_template = (string) 'cadou_email_template'; // this code we have mentioned in the email_templates.xml } $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); /*$this->messageManager->addSuccess( __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.') );*/ return TRUE; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())); return FALSE; } }
protected function _sendEmail($from, $to, $templateId, $vars, $store, $area = \Magento\Framework\App\Area::AREA_FRONTEND) { $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => $area, 'store' => $store->getId()])->setTemplateVars($vars)->setFrom($from)->addTo($to['email'], $to['name']); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); }
/** * Send Log Clean Warnings * * @return $this */ protected function _sendLogCleanEmail() { if (!$this->_errors) { return $this; } if (!$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return $this; } $this->inlineTranslation->suspend(); $transport = $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setTemplateVars(['warnings' => join("\n", $this->_errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); return $this; }
public function execute() { $email = $this->getRequest()->getParam('email'); // $this->_objectManager->get('Ebizmarts\Mandrill\Helper\Data')->sendTestEmail($email); $template = "mandrill_test_template"; $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setFrom($this->_objectManager->get('Ebizmarts\\Mandrill\\Helper\\Data')->getTestSender())->addTo($email)->setTemplateVars([])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1])->getTransport(); $transport->sendMessage(); $response = new Object(); $response->setError(0); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($response->toArray()); return $resultJson; }
public function execute() { $email = $this->getRequest()->getParam('email'); $this->_transportBuilder->setTemplateIdentifier(self::EMAIL_TEMPLATE_TEST_ID); $this->_transportBuilder->setFrom($this->_helper->getTestSender()); $this->_transportBuilder->addTo($email); $this->_transportBuilder->setTemplateVars([]); $this->_transportBuilder->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1]); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData(['error' => 0]); return $resultJson; }
/** * @param mixed $schedule * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function scheduledUpdateCurrencyRates($schedule) { $importWarnings = []; if (!$this->_scopeConfig->getValue(self::IMPORT_ENABLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::CRON_STRING_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return; } $errors = []; $rates = []; $service = $this->_scopeConfig->getValue(self::IMPORT_SERVICE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($service) { try { $importModel = $this->_importFactory->create($service); $rates = $importModel->fetchRates(); $errors = $importModel->getMessages(); } catch (\Exception $e) { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('We can\'t initialize the import model.'); } } else { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('Please specify the correct Import Service.'); } if (sizeof($errors) > 0) { foreach ($errors as $error) { $importWarnings[] = __('WARNING:') . ' ' . $error; } } if (sizeof($importWarnings) == 0) { $this->_currencyFactory->create()->saveRates($rates); } else { $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $importWarnings)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); } }
protected function _sendPopupCoupon($storeId) { $templateId = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_TEMPLATE_XML_PATH, $storeId); $mailSubject = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_MAIL_SUBJECT, $storeId); $tags = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_MANDRILL_TAG, $storeId) . "_{$storeId}"; $senderId = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::SENDER, $storeId); $sender = array('name' => $this->_helper->getConfig("trans_email/ident_{$senderId}/name", $storeId), 'email' => $this->_helper->getConfig("trans_email/ident_{$senderId}/email", $storeId)); //coupon vars $this->couponamount = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_DISCOUNT, $storeId); $this->couponexpiredays = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_EXPIRE, $storeId); $this->coupontype = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_DISCOUNTTYPE, $storeId); $this->couponlength = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_LENGTH, $storeId); $this->couponlabel = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_LABEL, $storeId); $collection = $this->_objectManager->create('Ebizmarts\\AbandonedCart\\Model\\Popup')->getCollection()->addFieldToFilter('email', array('neq' => ''))->addFieldToFilter('processed', array('eq' => 0)); $mandrillHelper = $this->_objectManager->create('Ebizmarts\\Mandrill\\Helper\\Data'); foreach ($collection as $item) { $email = $item->getEmail(); $emailArr = explode('@', $email); $pseudoName = $emailArr[0]; if ($this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_AUTOMATIC, $storeId) == 2) { list($couponCode, $discount, $toDate) = $this->_createNewCoupon($storeId, $email); $vars = array('couponcode' => $couponCode, 'discount' => $discount, 'todate' => $toDate, 'name' => $pseudoName, 'tags' => array($tags)); } else { $couponCode = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_CODE); $vars = array('couponcode' => $couponCode, 'name' => $pseudoName, 'tags' => array($tags)); } $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => $storeId])->setSubject($mailSubject)->setTemplateVars($vars)->setFrom($sender)->addTo($email, $pseudoName)->getTransport(); $transport->sendMessage(); $item->setProcessed(1)->save(); $mandrillHelper->saveMail('review coupon', $email, $pseudoName, $couponCode, $storeId); } }
/** * Generate sitemaps * * @return void * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function scheduledGenerateSitemaps() { $errors = []; // check if scheduled generation enabled if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_GENERATION_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return; } $collection = $this->_collectionFactory->create(); /* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */ foreach ($collection as $sitemap) { /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ try { $sitemap->generateXml(); } catch (\Exception $e) { $errors[] = $e->getMessage(); } } if ($errors && $this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { $translate = $this->_translateModel->getTranslateInline(); $this->_translateModel->setTranslateInline(false); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); } }
public function informCustomer(\Magento\Sales\Model\Order $order, $amount, $currency) { try { if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray())) { return false; } $siteUrl = $order->getStore()->getBaseUrl(); $siteName = $this->_helper->getStoreName(); $supportEmail = $this->_helper->getStoreConfig('trans_email/ident_support/email'); $supportName = $this->_helper->getStoreConfig('trans_email/ident_support/name'); $payment_details_arr['site_url'] = $siteUrl; $payment_details_arr['order_increment_id'] = $order_increment_id; $payment_details_arr['site_name'] = $siteName; $payment_details_arr['customer_name'] = $order->getCustomerName(); $payment_details_arr['order_date'] = $order->getCreatedAtFormatted(\IntlDateFormatter::LONG); $payment_details_arr['support_email'] = $supportEmail; $payment_details_arr['total_paid'] = number_format($amount / 100, 2); $payment_details_arr['currency'] = $currency; $transport = $this->_transportBuilder->setTemplateIdentifier($method_config['smart2pay_email_payment_confirmation'])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => $order->getStore()->getId()])->setTemplateVars($payment_details_arr)->setFrom(['name' => $supportName, 'email' => $supportEmail])->addTo($order->getCustomerEmail())->getTransport(); $transport->sendMessage(); } catch (\Magento\Framework\Exception\MailException $e) { $this->_s2pLogger->write('Error sending customer informational email to [' . $order->getCustomerEmail() . ']', 'email_template'); $this->_s2pLogger->write($e->getMessage(), 'email_exception'); } catch (\Exception $e) { $this->_s2pLogger->write($e->getMessage(), 'exception'); } return true; }
/** * Send corresponding email template * * @param CustomerInterface $customer * @param string $template configuration path of email template * @param string $sender configuration path of email identity * @param array $templateParams * @param int|null $storeId * @param string $email * @return void */ private function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null, $email = null) { $templateId = $this->scopeConfig->getValue($template, 'store', $storeId); if ($email === null) { $email = $customer->getEmail(); } $transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => 'frontend', 'store' => $storeId])->setTemplateVars($templateParams)->setFrom($this->scopeConfig->getValue($sender, 'store', $storeId))->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport(); $transport->sendMessage(); }
/** * Send corresponding email template * * @param CustomerInterface $customer * @param string $template configuration path of email template * @param string $sender configuration path of email identity * @param array $templateParams * @param int|null $storeId * @param string $email * @return $this */ protected function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null, $email = null) { $templateId = $this->scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId); if ($email === null) { $email = $customer->getEmail(); } $transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars($templateParams)->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport(); $transport->sendMessage(); return $this; }
/** * @dataProvider getTransportDataProvider * @param int $templateType * @param string $messageType * @param string $bodyText */ public function testGetTransport($templateType, $messageType, $bodyText) { $vars = ['reason' => 'Reason', 'customer' => 'Customer']; $options = ['area' => 'frontend', 'store' => 1]; $template = $this->getMock('\\Magento\\Framework\\Mail\\TemplateInterface'); $template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->will($this->returnSelf()); $template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->will($this->returnSelf()); $template->expects($this->once())->method('getSubject')->will($this->returnValue('Email Subject')); $template->expects($this->once())->method('getType')->will($this->returnValue($templateType)); $template->expects($this->once())->method('processTemplate')->will($this->returnValue($bodyText)); $this->templateFactoryMock->expects($this->once())->method('get')->with($this->equalTo('identifier'))->will($this->returnValue($template)); $this->messageMock->expects($this->once())->method('setSubject')->with($this->equalTo('Email Subject'))->will($this->returnSelf()); $this->messageMock->expects($this->once())->method('setMessageType')->with($this->equalTo($messageType))->will($this->returnSelf()); $this->messageMock->expects($this->once())->method('setBody')->with($this->equalTo($bodyText))->will($this->returnSelf()); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->_mailTransportFactoryMock->expects($this->at(0))->method('create')->with($this->equalTo(['message' => $this->messageMock]))->will($this->returnValue($transport)); $this->objectManagerMock->expects($this->at(0))->method('create')->with($this->equalTo('Magento\\Framework\\Mail\\Message'))->will($this->returnValue($transport)); $this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options); $result = $this->builder->getTransport(); $this->assertInstanceOf('Magento\\Framework\\Mail\\TransportInterface', $result); }
/** * @param $storeId */ public function _processBirthday($storeId) { $days = $this->_helper->getConfig(Config::BIRTHDAY_DAYS, $storeId); $customerGroups = explode(",", $this->_helper->getConfig(Config::BIRTHDAY_CUSTOMER_GROUPS, $storeId)); $senderId = $this->_helper->getConfig(Config::GENERAL_SENDER, $storeId); $sender = array('name' => $this->_helper->getConfig("trans_email/ident_{$senderId}/name", $storeId), 'email' => $this->_helper->getConfig("trans_email/ident_{$senderId}/email", $storeId)); $templateId = $this->_helper->getConfig(Config::BIRTHDAY_TEMPLATE, $storeId); $mailSubject = $this->_helper->getConfig(Config::BIRTHDAY_SUBJECT, $storeId); $tags = $this->_helper->getConfig(Config::BIRTHDAY_MANDRILL_TAG, $storeId) . "_{$storeId}"; $sendCoupon = $this->_helper->getConfig(Config::BIRTHDAY_COUPON, $storeId); $customerGroupsCoupon = explode(",", $this->_helper->getConfig(Config::BIRTHDAY_CUSTOMER_COUPON, $storeId)); $collection = $this->_customerCollection; $date2 = date("Y-m-d H:i:s", strtotime(" + {$days} days")); $month = date("m", strtotime($date2)); $day = date("d", strtotime($date2)); $moreSelect = "MONTH(at_dob.value) = {$month} AND DAY(at_dob.value) = {$day}"; $collection->addAttributeToFilter('dob', array('neq' => 'null'))->addFieldToFilter('store_id', array('eq' => $storeId)); if (count($customerGroups)) { $collection->addFieldToFilter('group_id', array('in' => $customerGroups)); } $collection->getSelect()->where($moreSelect); $mandrillHelper = $this->_objectManager->get('\\Ebizmarts\\Mandrill\\Helper\\Data'); foreach ($collection as $customer) { $cust = $this->_objectManager->create('Magento\\Customer\\Model\\Customer')->load($customer->getEntityId()); $email = $cust->getEmail(); $name = $cust->getFirstname() . ' ' . $cust->getLastname(); if ($mandrillHelper->isSubscribed($email, 'birthday', $storeId)) { $vars = array(); $url = $this->_storeManager->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'mandrill/autoresponder/unsubscribe?list=birthday&email=' . $email . '&store=' . $storeId; $couponCode = ''; if ($sendCoupon && in_array($customer->getGroupId(), $customerGroupsCoupon)) { if ($this->_helper->getConfig(Config::BIRTHDAY_AUTOMATIC, $storeId) == Config::COUPON_AUTOMATIC) { $this->_couponAmount = $this->_helper->getConfig(Config::BIRTHDAY_DISCOUNT, $storeId); $this->_couponExpireDays = $this->_helper->getConfig(Config::BIRTHDAY_EXPIRE, $storeId); $this->_couponType = $this->_helper->getConfig(Config::BIRTHDAY_DISCOUNT_TYPE, $storeId); $this->_couponLength = $this->_helper->getConfig(Config::BIRTHDAY_LENGTH, $storeId); $this->_couponLabel = $this->_helper->getConfig(Config::BIRTHDAY_COUPON_LABEL, $storeId); list($couponCode, $discount, $toDate) = $this->_createNewCoupon($storeId, $email, 'Birthday coupon'); $vars = array('couponcode' => $couponCode, 'discount' => $discount, 'todate' => $toDate, 'name' => $name, 'tags' => array($tags), 'url' => $url); } else { $couponCode = $this->_helper->getConfig(Config::BIRTHDAY_COUPON_CODE); $vars = array('couponcode' => $couponCode, 'name' => $name, 'tags' => array($tags), 'url' => $url); } } $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $storeId])->setTemplateVars($vars)->setFrom($sender)->addTo($email, $name)->getTransport(); $transport->sendMessage(); $mandrillHelper->saveMail('happy birthday', $email, $name, $couponCode, $storeId); } } }
/** * @return $this * @throws CoreException */ public function send() { if ($this->isExceedLimit()) { throw new \Magento\Framework\Exception\LocalizedException(__('You\'ve met your limit of %1 sends in an hour.', $this->getMaxSendsToFriend())); } $this->inlineTranslation->suspend(); $message = nl2br(htmlspecialchars($this->getSender()->getMessage())); $sender = ['name' => $this->_escaper->escapeHtml($this->getSender()->getName()), 'email' => $this->_escaper->escapeHtml($this->getSender()->getEmail())]; foreach ($this->getRecipients()->getEmails() as $k => $email) { $name = $this->getRecipients()->getNames($k); $this->_transportBuilder->setTemplateIdentifier($this->_sendfriendData->getEmailTemplate())->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setFrom($sender)->setTemplateVars(['name' => $name, 'email' => $email, 'product_name' => $this->getProduct()->getName(), 'product_url' => $this->getProduct()->getUrlInStore(), 'message' => $message, 'sender_name' => $sender['name'], 'sender_email' => $sender['email'], 'product_image' => $this->_catalogImage->init($this->getProduct(), 'sendfriend_small_image')->getUrl()])->addTo($email, $name); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); $this->_incrementSentCount(); return $this; }
/** * @param \Magento\Framework\DataObject $postObject * * @return bool * @throws \Exception */ public function sendrequest($postObject) { if (!filter_var($postObject->getData('to'), FILTER_VALIDATE_EMAIL)) { throw new \Exception($this->_dataHelper->__('Please enter a valid e-mail address.')); } if (strlen(trim($postObject->getData('replyto')))) { if (!filter_var($postObject->getData('replyto'), FILTER_VALIDATE_EMAIL)) { throw new \Exception($this->_dataHelper->__('Please enter a valid e-mail address (reply to).')); } $this->_transportBuilder->setReplyTo(trim($postObject->getData('replyto'))); } $sender = ['name' => $this->_dataHelper->getStoreConfigData('trans_email/ident_general/name'), 'email' => $this->_dataHelper->getStoreConfigData('trans_email/ident_general/email')]; if (!strlen($sender['email'])) { throw new \Exception('Please set your shop e-mail address!'); } $modules = []; foreach ($this->_moduleLoader->load() as $module) { if (!in_array($module['name'], $this->_moduleBlacklist)) { $modules[] = $module['name']; } } natsort($modules); $payments = $this->_paymentConfig->getActiveMethods(); /** @var \Magento\Framework\App\Config\Data $cfg */ $cfg = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_STORE); $foreign = array(); $mine = array(); foreach ($payments as $paymentCode => $paymentModel) { /** @var AbstractPayment $paymentModel */ $method = array('label' => $paymentModel->getTitle(), 'value' => $paymentCode, 'config' => []); if (preg_match('/^wirecard_/i', $paymentCode)) { $method['config'] = $cfg->getValue('payment/' . $paymentCode); $mine[$paymentCode] = $method; } else { $foreign[$paymentCode] = $method; } } $versioninfo = new \Magento\Framework\DataObject(); $versioninfo->setData($this->_dataHelper->getVersionInfo()); $transport = $this->_transportBuilder->setTemplateIdentifier('contact_support_email')->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['data' => $postObject, 'modules' => $modules, 'foreign' => $foreign, 'mine' => $mine, 'configstr' => $this->_dataHelper->getConfigString(), 'versioninfo' => $versioninfo])->setFrom($sender)->addTo($postObject->getData('to'))->getTransport(); $transport->sendMessage(); return true; }
/** * Send email id payment was failed * * @param \Magento\Sales\Model\Quote $checkout * @param string $message * @param string $checkoutType * @return $this */ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') { $this->inlineTranslation->suspend(); $template = $this->_scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId()); $copyMethod = $this->_scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $bcc = array(); if ($copyTo && $copyMethod == 'bcc') { $bcc = $copyTo; } $_receiver = $this->_scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $sendTo = array(array('email' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))); if ($copyTo && $copyMethod == 'copy') { foreach ($copyTo as $email) { $sendTo[] = array('email' => $email, 'name' => null); } } $shippingMethod = ''; if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) { $data = explode('_', $shippingInfo); $shippingMethod = $data[0]; } $paymentMethod = ''; if ($paymentInfo = $checkout->getPayment()) { $paymentMethod = $paymentInfo->getMethod(); } $items = ''; foreach ($checkout->getAllVisibleItems() as $_item) { /* @var $_item \Magento\Sales\Model\Quote\Item */ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n"; } $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal(); foreach ($sendTo as $recipient) { $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->setTemplateVars(array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->_scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->_scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total))->setFrom($this->_scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); return $this; }
/** * Sends out unsubscription email * * @return $this */ public function sendUnsubscriptionEmail() { if ($this->getImportMode()) { return $this; } if (!$this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return $this; } $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setTemplateVars(['subscriber' => $this])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->getEmail(), $this->getName()); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); return $this; }
/** * Send corresponding email template * * @param CustomerInterface $customer * @param string $template configuration path of email template * @param string $sender configuration path of email identity * @param array $templateParams * @param int|null $storeId * @return $this */ protected function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null) { /** @var \Magento\Framework\Mail\TransportInterface $transport */ $transport = $this->transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue($template, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars($templateParams)->setFrom($this->scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))->getTransport(); $transport->sendMessage(); return $this; }
/** * Share wishlist * * @return ResponseInterface|void * @throws NotFoundException */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { return $this->_redirect('*/*/'); } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = explode(',', $this->getRequest()->getPost('emails')); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Email address can\'t be empty.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wishlist can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); return; } $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); /*if share rss added rss feed to email template*/ if ($this->getRequest()->getParam('rss_url')) { $rss_url = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Rss')->setWishlistId($wishlist->getId())->toHtml(); $message .= $rss_url; } $wishlistBlock = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Items')->toHtml(); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { $scopeConfig = $this->_objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $storeManager = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface'); foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeManager->getStore()->getStoreId()))->setTemplateVars(array('customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $wishlistBlock, 'addAllLink' => $this->_url->getUrl('*/shared/allcart', array('code' => $sharingCode)), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', array('code' => $sharingCode)), 'message' => $message, 'store' => $storeManager->getStore()))->setFrom($scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', array('wishlist' => $wishlist)); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $this->_redirect('*/*', array('wishlist_id' => $wishlist->getId())); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); } }
/** * Send customer email * * @return bool * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function send() { if ($this->_website === null || $this->_customer === null) { return false; } if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) { return false; } if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) { return false; } if ($this->_customer->getStoreId() > 0) { $store = $this->_storeManager->getStore($this->_customer->getStoreId()); } else { $store = $this->_website->getDefaultStore(); } $storeId = $store->getId(); if ($this->_type == 'price' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) { return false; } elseif ($this->_type == 'stock' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) { return false; } if ($this->_type != 'price' && $this->_type != 'stock') { return false; } $this->_appEmulation->startEnvironmentEmulation($storeId); if ($this->_type == 'price') { $this->_getPriceBlock()->setStore($store)->reset(); foreach ($this->_priceProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getPriceBlock()->addProduct($product); } $block = $this->_getPriceBlock(); $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); } else { $this->_getStockBlock()->setStore($store)->reset(); foreach ($this->_stockProducts as $product) { $product->setCustomerGroupId($this->_customer->getGroupId()); $this->_getStockBlock()->addProduct($product); } $block = $this->_getStockBlock(); $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); } $alertGrid = $this->_appState->emulateAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND, [$block, 'toHtml']); $this->_appEmulation->stopEnvironmentEmulation(); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars(['customerName' => $this->_customerHelper->getCustomerName($this->_customer), 'alertGrid' => $alertGrid])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->_customer->getEmail(), $this->_customerHelper->getCustomerName($this->_customer))->getTransport(); $transport->sendMessage(); return true; }
/** * Send user notification email * * @param string $changes * @param string $email * @return $this */ protected function sendUserNotificationEmail($changes, $email = null) { if ($email === null) { $email = $this->getEmail(); } $transport = $this->_transportBuilder->setTemplateIdentifier($this->_config->getValue(self::XML_PATH_USER_NOTIFICATION_TEMPLATE))->setTemplateModel('Magento\\Email\\Model\\BackendTemplate')->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => Store::DEFAULT_STORE_ID])->setTemplateVars(['user' => $this, 'store' => $this->_storeManager->getStore(Store::DEFAULT_STORE_ID), 'changes' => $changes])->setFrom($this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY))->addTo($email, $this->getName())->getTransport(); $transport->sendMessage(); return $this; }
/** * Send email to when password is resetting * * @return $this */ public function sendPasswordResetNotificationEmail() { // Set all required params and send emails /** @var \Magento\Framework\Mail\TransportInterface $transport */ $transport = $this->_transportBuilder->setTemplateIdentifier($this->_config->getValue(self::XML_PATH_RESET_PASSWORD_TEMPLATE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 0))->setTemplateVars(array('user' => $this, 'store' => $this->_storeManager->getStore(0)))->setFrom($this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY))->addTo($this->getEmail(), $this->getName())->getTransport(); $transport->sendMessage(); return $this; }
/** * Send email to administrator if error * * @return $this */ protected function _sendErrorEmail() { if (count($this->_errors)) { if (!$this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return $this; } $this->inlineTranslation->suspend(); $transport = $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $this->_errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); $this->_errors[] = []; } return $this; }
/** * Share wishlist * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->_formKeyValidator->validate($this->getRequest())) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = $this->getRequest()->getPost('emails'); $emails = empty($emails) ? $emails : explode(',', $emails); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Please enter an email address.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wish list can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); $this->addLayoutHandles($resultLayout); $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); $message .= $this->getRssLink($wishlist->getId(), $resultLayout); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getStoreId()])->setTemplateVars(['customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $this->getWishlistItems($resultLayout), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', ['code' => $sharingCode]), 'message' => $message, 'store' => $this->storeManager->getStore()])->setFrom($this->scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', ['wishlist' => $wishlist]); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } }
/** * Send email with order update information * * @param boolean $notifyCustomer * @param string $comment * @return $this */ public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '') { $storeId = $this->getStore()->getId(); if (!$this->_salesData->canSendOrderCommentEmail($storeId)) { return $this; } // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO); $copyMethod = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); // Check if at least one recipient is found if (!$notifyCustomer && !$copyTo) { return $this; } // Retrieve corresponding email template id and customer name if ($this->getCustomerIsGuest()) { $templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $customerName = $this->getBillingAddress()->getName(); } else { $templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $customerName = $this->getCustomerName(); } if ($notifyCustomer) { $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->getCustomerEmail(), $customerName); if ($copyTo && $copyMethod == 'bcc') { // Add bcc to customer email foreach ($copyTo as $email) { $this->_transportBuilder->addBcc($email); } } /** @var \Magento\Framework\Mail\TransportInterface $transport */ $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); } // Email copies are sent as separated emails if their copy method is // 'copy' or a customer should not be notified if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) { foreach ($copyTo as $email) { $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($email)->getTransport()->sendMessage(); } } return $this; }
/** * Send email to when password is resetting * * @return $this */ public function sendPasswordResetNotificationEmail() { $templateId = $this->_config->getValue(self::XML_PATH_RESET_PASSWORD_TEMPLATE); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId) ->setTemplateModel('Magento\Email\Model\BackendTemplate') ->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => Store::DEFAULT_STORE_ID]) ->setTemplateVars(['user' => $this, 'store' => $this->_storeManager->getStore(Store::DEFAULT_STORE_ID)]) ->setFrom($this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY)) ->addTo($this->getEmail(), $this->getName()) ->getTransport(); $transport->sendMessage(); return $this; }
/** * Send email to when password is resetting * * @return $this */ public function sendPasswordResetNotificationEmail() { $storeId = $this->getStoreId(); if (!$storeId) { $storeId = $this->_getWebsiteStoreId(); } /** @var \Magento\Framework\Mail\TransportInterface $transport */ $transport = $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_RESET_PASSWORD_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('customer' => $this, 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->getEmail(), $this->getName())->getTransport(); $transport->sendMessage(); return $this; }