<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Service;
use Customize\Repository\SchoolRepository;
use Eccube\Service\MailService as BaseMailService;
use Eccube\Entity\Customer;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\MailHistory;
use Eccube\Entity\MailTemplate;
use Eccube\Entity\Order;
use Eccube\Entity\OrderItem;
use Eccube\Entity\Shipping;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Repository\MailTemplateRepository;
use Eccube\Repository\MailHistoryRepository;
use Eccube\Repository\BaseInfoRepository;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Address;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class MailService extends BaseMailService
{
/**
* @var MailerInterface
*/
protected $mailer;
/**
* @var MailTemplateRepository
*/
protected $mailTemplateRepository;
/**
* @var MailHistoryRepository
*/
protected $mailHistoryRepository;
/**
* @var \SchoolRepository
*/
protected $schoolRepository;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* @var \Twig\Environment
*/
protected $twig;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/** @var ContainerInterface */
protected $container;
/**
* @var EventDispatcher
*/
protected $eventDispatcher;
/**
* @var TokenStorageInterface
*/
protected $tokenStorage;
/**
* @var SessionInterface
*/
protected $session;
/**
* MailService constructor.
* @param SchoolRepository $schoolRepository
*/
public function __construct(
MailerInterface $mailer,
MailTemplateRepository $mailTemplateRepository,
MailHistoryRepository $mailHistoryRepository,
EccubeConfig $eccubeConfig,
\Twig\Environment $twig,
BaseInfoRepository $baseInfoRepository,
ContainerInterface $container,
EventDispatcherInterface $eventDispatcher,
TokenStorageInterface $tokenStorage,
SchoolRepository $schoolRepository,
SessionInterface $session
) {
$this->mailer = $mailer;
$this->mailTemplateRepository = $mailTemplateRepository;
$this->mailHistoryRepository = $mailHistoryRepository;
$this->eccubeConfig = $eccubeConfig;
$this->twig = $twig;
$this->BaseInfo = $baseInfoRepository->get();
$this->container = $container;
$this->eventDispatcher = $eventDispatcher;
$this->tokenStorage = $tokenStorage;
$this->schoolRepository = $schoolRepository;
$this->session = $session;
}
/**
* Send customer confirm mail.
*
* @param $Customer 会員情報
* @param string $activateUrl アクティベート用url
*/
public function sendCustomerConfirmMail(Customer $Customer, $activateUrl)
{
log_info('仮会員登録メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
]);
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_CONFIRM);
try {
$this->mailer->send($message);
log_info('仮会員登録メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send customer complete mail.
*
* @param $Customer 会員情報
*/
public function sendCustomerCompleteMail(Customer $Customer)
{
log_info('会員登録完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_complete_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// foreach($to_addresses as $ta) {
// $message->addBcc($ta);
// }
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_COMPLETE);
try {
$this->mailer->send($message);
log_info('会員登録完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send withdraw mail.
*
* @param $Customer Customer
* @param $email string
*/
public function sendCustomerWithdrawMail(Customer $Customer, string $email)
{
log_info('退会手続き完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_customer_withdraw_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($email))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'email' => $email,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_WITHDRAW);
try {
$this->mailer->send($message);
log_info('退会手続き完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send contact mail.
*
* @param $formData お問い合わせ内容
*/
public function sendContactMail($formData, $Customer)
{
log_info('お問い合わせ受付メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_contact_mail_template_id']);
$formData['admission_year'] = $Customer && $Customer->getAdmissionYear() ? $Customer->getAdmissionYear() : null;
$body = $this->twig->render($MailTemplate->getFileName(), [
'data' => $formData,
'BaseInfo' => $this->BaseInfo,
]);
$school = $formData['school'];
$to_addresses = [$this->BaseInfo->getEmail02()];
if($school && $school->getSchoolEmail()) {
$to_addresses[] = $school->getSchoolEmail();
}
// 問い合わせ者にメール送信
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail02(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($formData['email']))
->replyTo($this->BaseInfo->getEmail02())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'data' => $formData,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'formData' => $formData,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CONTACT);
try {
$this->mailer->send($message);
log_info('お問い合わせ受付メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send order mail.
*
* @param \Eccube\Entity\Order $Order 受注情報
*
* @return \Email
*/
public function sendOrderMail(Order $Order)
{
log_info('受注メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Order' => $Order,
]);
$Customer = $Order->getCustomer();
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Order' => $Order,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Order' => $Order,
'MailTemplate' => $MailTemplate,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ORDER);
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
$MailHistory = new MailHistory();
$MailHistory->setMailSubject($message->getSubject())
->setMailBody($message->getTextBody())
->setOrder($Order)
->setSendDate(new \DateTime());
// HTML用メールの設定
$htmlBody = $message->getHtmlBody();
if (!empty($htmlBody)) {
$MailHistory->setMailHtmlBody($htmlBody);
}
$this->mailHistoryRepository->save($MailHistory);
log_info('受注メール送信完了');
return $message;
}
/**
* Send admin customer confirm mail.
*
* @param $Customer 会員情報
* @param string $activateUrl アクティベート用url
*/
public function sendAdminCustomerConfirmMail(Customer $Customer, $activateUrl)
{
log_info('仮会員登録再送メール送信開始');
/* @var $MailTemplate \Eccube\Entity\MailTemplate */
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'activateUrl' => $activateUrl,
]);
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'activateUrl' => $activateUrl,
]);
$message
->text($body)
->html($htmlBody);;
} else {
$message->setBody($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM);
$count = $this->mailer->send($message);
log_info('仮会員登録再送メール送信完了', ['count' => $count]);
}
/**
* Send admin order mail.
*
* @param Order $Order 受注情報
* @param $formData 入力内容
*
* @return \Email
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function sendAdminOrderMail(Order $Order, $formData)
{
log_info('受注管理通知メール送信開始');
$Customer = $Order->getCustomer();
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$formData['mail_subject'])
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04())
->text($formData['tpl_data']);
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
$event = new EventArgs(
[
'message' => $message,
'Order' => $Order,
'formData' => $formData,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ADMIN_ORDER);
try {
$this->mailer->send($message);
log_info('受注管理通知メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
return $message;
}
/**
* Send password reset notification mail.
*
* @param $Customer 会員情報
* @param string $reset_url
*/
public function sendPasswordResetNotificationMail(Customer $Customer, $reset_url)
{
log_info('パスワード再発行メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_forgot_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
'reset_url' => $reset_url,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
'reset_url' => $reset_url,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'resetUrl' => $reset_url,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_PASSWORD_RESET);
try {
$this->mailer->send($message);
log_info('パスワード再発行メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send password reset notification mail.
*
* @param $Customer 会員情報
* @param string $password
*/
public function sendPasswordResetCompleteMail(Customer $Customer, $password)
{
log_info('パスワード変更完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_reset_complete_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'password' => $password,
]);
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'password' => $password,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'password' => $password,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_PASSWORD_RESET_COMPLETE);
try {
$this->mailer->send($message);
log_info('パスワード変更完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* 発送通知メールを送信する.
* 発送通知メールは受注ごとに送られる
*
* @param Shipping $Shipping
*
* @throws \Twig_Error
*/
public function sendShippingNotifyMail(Shipping $Shipping, $deliveryNote = false, $pdfPath = null)
{
log_info('出荷通知メール送信処理開始', ['id' => $Shipping->getId()]);
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
/** @var Order $Order */
$Order = $Shipping->getOrder();
$body = $this->getShippingNotifyMailBody($Shipping, $Order, $MailTemplate->getFileName());
$Customer = $Order->getCustomer();
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addTo($this->convertRFCViolatingEmail($ta));
$message->addBcc($ta);
}
if ($deliveryNote && $pdfPath) {
$message->attachFromPath($pdfPath);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->getShippingNotifyMailBody($Shipping, $Order, $htmlFileName, true);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
$MailHistory = new MailHistory();
$MailHistory->setMailSubject($message->getSubject())
->setMailBody($message->getTextBody())
->setOrder($Order)
->setSendDate(new \DateTime());
// HTML用メールの設定
$htmlBody = $message->getHtmlBody();
if (!empty($htmlBody)) {
$MailHistory->setMailHtmlBody($htmlBody);
}
$this->mailHistoryRepository->save($MailHistory);
log_info('出荷通知メール送信処理完了', ['id' => $Shipping->getId()]);
}
/**
* Send Temporary order mail.
*
* @param \Eccube\Entity\Order $Order 受注情報
* @return string
*/
public function sendOrderTemporaryMail(\Eccube\Entity\Order $Order)
{
log_info('仮受注メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find(9);//仮注文受付メール
$Customer = $Order->getCustomer() ? $Order->getCustomer() : $this->tokenStorage->getToken()->getUser();
if($Customer->getSchool()) {
$schoolId = $Customer->getSchool()->getSchoolId();
if ($schoolId !== null) {
$school = $this->schoolRepository->find($schoolId);
if ($school->getSchoolMeasuringDate()) {
$measuringDate = $school->getSchoolMeasuringDate()->format('Y年m月d日');
} else {
$measuringDate = '';
}
}
}else{
$measuringDate = '';
}
$body = $this->twig->render($MailTemplate->getFileName(), array(
'Order' => $Order,
'MeasuringDate' => $measuringDate,
));
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addTo($this->convertRFCViolatingEmail($ta));
$message->addBcc($ta);
}
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Order' => $Order,
'MeasuringDate' => $measuringDate,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
array(
'message' => $message,
'Order' => $Order,
'MailTemplate' => $MailTemplate,
'BaseInfo' => $this->BaseInfo,
),
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ORDER);
$count = $this->mailer->send($message);
if($this->session->get('is_temporary_order')){
log_info('仮注文受付メール送信完了', array('count' => $count));
}else{
log_info('仮受注メール送信完了', array('count' => $count));
}
return $body;
}
/**
* Send Reserve mail.
*
* @param \Customize\Entity\Reserve $Reserve 受注情報
* @return string
*/
public function sendReserveMail(\Customize\Entity\Reserve $Reserve, $mode='new', $kubun=2, $Store, $School)
{
log_info('予約メール送信開始');
if($mode == 'new')
$mail_temmplate_id = 10;
elseif($mode == 'cancel')
$mail_temmplate_id = 11;
elseif($mode == 'change')
$mail_temmplate_id = 12;
$MailTemplate = $this->mailTemplateRepository->find($mail_temmplate_id);//予約受付メール
$Customer = $this->tokenStorage->getToken()->getUser();
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
$body = $this->twig->render($MailTemplate->getFileName(), array(
'Reserve' => $Reserve,
'kubun' => $kubun,
'Store' => $Store,
'School' => $School
));
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Reserve' => $Reserve,
'kubun' => $kubun,
'Store' => $Store,
'School' => $School
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$count = $this->mailer->send($message);
}
public function sendCustomMail($Shipping, $template_id){
log_info('受注メール送信開始');
$Order = $Shipping->getOrder();
$MailTemplate = $this->mailTemplateRepository->find($template_id);
$historyUrl = is_null($Order->getCustomer())
? null
: $this->container->get('router')->generate('mypage_history',['order_no' => $Order->getOrderNo()],UrlGeneratorInterface::ABSOLUTE_URL);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Order' => $Order,
'Shipping' => $Shipping,
'isCvsPay' => false,
'historyUrl' => $historyUrl
]);
$Customer = $Order->getCustomer();
$to_addresses = [$this->BaseInfo->getEmail01()];
if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
$to_addresses[] = $Customer->getSchool()->getSchoolEmail();
}
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
foreach($to_addresses as $ta) {
$message->addBcc($ta);
}
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Order' => $Order,
'Shipping' => $Shipping,
'isCvsPay' => false,
'historyUrl' => $historyUrl
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Order' => $Order,
'MailTemplate' => $MailTemplate,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ORDER);
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
return $message;
}
}