app/Customize/Service/MailService.php line 943

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Service;
  13. use Customize\Repository\SchoolRepository;
  14. use Eccube\Service\MailService as BaseMailService;
  15. use Eccube\Entity\Customer;
  16. use Eccube\Common\EccubeConfig;
  17. use Eccube\Entity\BaseInfo;
  18. use Eccube\Entity\MailHistory;
  19. use Eccube\Entity\MailTemplate;
  20. use Eccube\Entity\Order;
  21. use Eccube\Entity\OrderItem;
  22. use Eccube\Entity\Shipping;
  23. use Eccube\Event\EccubeEvents;
  24. use Eccube\Event\EventArgs;
  25. use Eccube\Repository\MailTemplateRepository;
  26. use Eccube\Repository\MailHistoryRepository;
  27. use Eccube\Repository\BaseInfoRepository;
  28. use Symfony\Component\Mime\Email;
  29. use Symfony\Component\Mime\Address;
  30. use Symfony\Component\DependencyInjection\ContainerInterface;
  31. use Symfony\Component\EventDispatcher\EventDispatcher;
  32. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  33. use Symfony\Component\Mailer\MailerInterface;
  34. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  35. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  36. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  37. class MailService extends BaseMailService
  38. {
  39.     /**
  40.      * @var MailerInterface
  41.      */
  42.     protected $mailer;
  43.     /**
  44.      * @var MailTemplateRepository
  45.      */
  46.     protected $mailTemplateRepository;
  47.     /**
  48.      * @var MailHistoryRepository
  49.      */
  50.     protected $mailHistoryRepository;
  51.     /**
  52.      * @var \SchoolRepository
  53.      */
  54.     protected $schoolRepository;
  55.     /**
  56.      * @var EccubeConfig
  57.      */
  58.     protected $eccubeConfig;
  59.     /**
  60.      * @var \Twig\Environment
  61.      */
  62.     protected $twig;
  63.     /**
  64.      * @var BaseInfo
  65.      */
  66.     protected $BaseInfo;
  67.     /** @var ContainerInterface */
  68.     protected $container;
  69.     /**
  70.      * @var EventDispatcher
  71.      */
  72.     protected $eventDispatcher;
  73.     /**
  74.      * @var TokenStorageInterface
  75.      */
  76.     protected $tokenStorage;
  77.     /**
  78.      * @var SessionInterface
  79.      */
  80.     protected $session;
  81.     /**
  82.      * MailService constructor.
  83.      * @param SchoolRepository $schoolRepository
  84.      */
  85.     public function __construct(
  86.         MailerInterface $mailer,
  87.         MailTemplateRepository $mailTemplateRepository,
  88.         MailHistoryRepository $mailHistoryRepository,
  89.         EccubeConfig $eccubeConfig,
  90.         \Twig\Environment $twig,
  91.         BaseInfoRepository $baseInfoRepository,
  92.         ContainerInterface $container,
  93.         EventDispatcherInterface $eventDispatcher,
  94.         TokenStorageInterface $tokenStorage,
  95.         SchoolRepository $schoolRepository,
  96.         SessionInterface $session
  97.     ) {
  98.         $this->mailer $mailer;
  99.         $this->mailTemplateRepository $mailTemplateRepository;
  100.         $this->mailHistoryRepository $mailHistoryRepository;
  101.         $this->eccubeConfig $eccubeConfig;
  102.         $this->twig $twig;
  103.         $this->BaseInfo $baseInfoRepository->get();
  104.         $this->container $container;
  105.         $this->eventDispatcher $eventDispatcher;
  106.         $this->tokenStorage $tokenStorage;
  107.         $this->schoolRepository $schoolRepository;
  108.         $this->session $session;
  109.     }
  110.     /**
  111.      * Send customer confirm mail.
  112.      *
  113.      * @param $Customer 会員情報
  114.      * @param string $activateUrl アクティベート用url
  115.      */
  116.     public function sendCustomerConfirmMail(Customer $Customer$activateUrl)
  117.     {
  118.         log_info('仮会員登録メール送信開始');
  119.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
  120.         $body $this->twig->render($MailTemplate->getFileName(), [
  121.             'Customer' => $Customer,
  122.             'BaseInfo' => $this->BaseInfo,
  123.             'activateUrl' => $activateUrl,
  124.         ]);
  125.         $to_addresses = [$this->BaseInfo->getEmail01()];
  126.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  127.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  128.         }
  129.         $message = (new Email())
  130.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  131.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  132.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  133.             ->replyTo($this->BaseInfo->getEmail03())
  134.             ->returnPath($this->BaseInfo->getEmail04());
  135.         foreach($to_addresses as $ta) {
  136.             $message->addBcc($ta);
  137.         }
  138.         // HTMLテンプレートが存在する場合
  139.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  140.         if (!is_null($htmlFileName)) {
  141.             $htmlBody $this->twig->render($htmlFileName, [
  142.                 'Customer' => $Customer,
  143.                 'BaseInfo' => $this->BaseInfo,
  144.                 'activateUrl' => $activateUrl,
  145.             ]);
  146.             $message
  147.                 ->text($body)
  148.                 ->html($htmlBody);
  149.         } else {
  150.             $message->text($body);
  151.         }
  152.         $event = new EventArgs(
  153.             [
  154.                 'message' => $message,
  155.                 'Customer' => $Customer,
  156.                 'BaseInfo' => $this->BaseInfo,
  157.                 'activateUrl' => $activateUrl,
  158.             ],
  159.             null
  160.         );
  161.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_CONFIRM);
  162.         try {
  163.             $this->mailer->send($message);
  164.             log_info('仮会員登録メール送信完了');
  165.         } catch (TransportExceptionInterface $e) {
  166.             log_critical($e->getMessage());
  167.         }
  168.     }
  169.     /**
  170.      * Send customer complete mail.
  171.      *
  172.      * @param $Customer 会員情報
  173.      */
  174.     public function sendCustomerCompleteMail(Customer $Customer)
  175.     {
  176.         log_info('会員登録完了メール送信開始');
  177.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_complete_mail_template_id']);
  178.         $body $this->twig->render($MailTemplate->getFileName(), [
  179.             'Customer' => $Customer,
  180.             'BaseInfo' => $this->BaseInfo,
  181.         ]);
  182.         $to_addresses = [$this->BaseInfo->getEmail01()];
  183.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  184.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  185.         }
  186.         $message = (new Email())
  187.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  188.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  189.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  190.             ->replyTo($this->BaseInfo->getEmail03())
  191.             ->returnPath($this->BaseInfo->getEmail04());
  192. //        foreach($to_addresses as $ta) {
  193. //            $message->addBcc($ta);
  194. //        }
  195.         // HTMLテンプレートが存在する場合
  196.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  197.         if (!is_null($htmlFileName)) {
  198.             $htmlBody $this->twig->render($htmlFileName, [
  199.                 'Customer' => $Customer,
  200.                 'BaseInfo' => $this->BaseInfo,
  201.             ]);
  202.             $message
  203.                 ->text($body)
  204.                 ->html($htmlBody);
  205.         } else {
  206.             $message->text($body);
  207.         }
  208.         $event = new EventArgs(
  209.             [
  210.                 'message' => $message,
  211.                 'Customer' => $Customer,
  212.                 'BaseInfo' => $this->BaseInfo,
  213.             ],
  214.             null
  215.         );
  216.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_COMPLETE);
  217.         try {
  218.             $this->mailer->send($message);
  219.             log_info('会員登録完了メール送信完了');
  220.         } catch (TransportExceptionInterface $e) {
  221.             log_critical($e->getMessage());
  222.         }
  223.     }
  224.     /**
  225.      * Send withdraw mail.
  226.      *
  227.      * @param $Customer Customer
  228.      * @param $email string
  229.      */
  230.     public function sendCustomerWithdrawMail(Customer $Customerstring $email)
  231.     {
  232.         log_info('退会手続き完了メール送信開始');
  233.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_customer_withdraw_mail_template_id']);
  234.         $body $this->twig->render($MailTemplate->getFileName(), [
  235.             'Customer' => $Customer,
  236.             'BaseInfo' => $this->BaseInfo,
  237.         ]);
  238.         $to_addresses = [$this->BaseInfo->getEmail01()];
  239.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  240.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  241.         }
  242.         $message = (new Email())
  243.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  244.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  245.             ->to($this->convertRFCViolatingEmail($email))
  246.             ->replyTo($this->BaseInfo->getEmail03())
  247.             ->returnPath($this->BaseInfo->getEmail04());
  248.         foreach($to_addresses as $ta) {
  249.             $message->addBcc($ta);
  250.         }
  251.         // HTMLテンプレートが存在する場合
  252.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  253.         if (!is_null($htmlFileName)) {
  254.             $htmlBody $this->twig->render($htmlFileName, [
  255.                 'Customer' => $Customer,
  256.                 'BaseInfo' => $this->BaseInfo,
  257.             ]);
  258.             $message
  259.                 ->text($body)
  260.                 ->html($htmlBody);
  261.         } else {
  262.             $message->text($body);
  263.         }
  264.         $event = new EventArgs(
  265.             [
  266.                 'message' => $message,
  267.                 'Customer' => $Customer,
  268.                 'BaseInfo' => $this->BaseInfo,
  269.                 'email' => $email,
  270.             ],
  271.             null
  272.         );
  273.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_WITHDRAW);
  274.         try {
  275.             $this->mailer->send($message);
  276.             log_info('退会手続き完了メール送信完了');
  277.         } catch (TransportExceptionInterface $e) {
  278.             log_critical($e->getMessage());
  279.         }
  280.     }
  281.     /**
  282.      * Send contact mail.
  283.      *
  284.      * @param $formData お問い合わせ内容
  285.      */
  286.     public function sendContactMail($formData$Customer)
  287.     {
  288.         log_info('お問い合わせ受付メール送信開始');
  289.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_contact_mail_template_id']);
  290.         $formData['admission_year'] = $Customer && $Customer->getAdmissionYear() ? $Customer->getAdmissionYear() : null;
  291.         $body $this->twig->render($MailTemplate->getFileName(), [
  292.             'data' => $formData,
  293.             'BaseInfo' => $this->BaseInfo,
  294.         ]);
  295.         $school $formData['school'];
  296.         $to_addresses = [$this->BaseInfo->getEmail02()];
  297.         if($school && $school->getSchoolEmail()) {
  298.             $to_addresses[] = $school->getSchoolEmail();
  299.         }
  300.         // 問い合わせ者にメール送信
  301.         $message = (new Email())
  302.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  303.             ->from(new Address($this->BaseInfo->getEmail02(), $this->BaseInfo->getShopName()))
  304.             ->to($this->convertRFCViolatingEmail($formData['email']))
  305.             ->replyTo($this->BaseInfo->getEmail02())
  306.             ->returnPath($this->BaseInfo->getEmail04());
  307.         foreach($to_addresses as $ta) {
  308.             $message->addBcc($ta);
  309.         }
  310.         // HTMLテンプレートが存在する場合
  311.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  312.         if (!is_null($htmlFileName)) {
  313.             $htmlBody $this->twig->render($htmlFileName, [
  314.                 'data' => $formData,
  315.                 'BaseInfo' => $this->BaseInfo,
  316.             ]);
  317.             $message
  318.                 ->text($body)
  319.                 ->html($htmlBody);
  320.         } else {
  321.             $message->text($body);
  322.         }
  323.         $event = new EventArgs(
  324.             [
  325.                 'message' => $message,
  326.                 'formData' => $formData,
  327.                 'BaseInfo' => $this->BaseInfo,
  328.             ],
  329.             null
  330.         );
  331.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CONTACT);
  332.         try {
  333.             $this->mailer->send($message);
  334.             log_info('お問い合わせ受付メール送信完了');
  335.         } catch (TransportExceptionInterface $e) {
  336.             log_critical($e->getMessage());
  337.         }
  338.     }
  339.     /**
  340.      * Send order mail.
  341.      *
  342.      * @param \Eccube\Entity\Order $Order 受注情報
  343.      *
  344.      * @return \Email
  345.      */
  346.     public function sendOrderMail(Order $Order)
  347.     {
  348.         log_info('受注メール送信開始');
  349.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_mail_template_id']);
  350.         $body $this->twig->render($MailTemplate->getFileName(), [
  351.             'Order' => $Order,
  352.         ]);
  353.         $Customer $Order->getCustomer();
  354.         $to_addresses = [$this->BaseInfo->getEmail01()];
  355.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  356.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  357.         }
  358.         $message = (new Email())
  359.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  360.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  361.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  362.             ->replyTo($this->BaseInfo->getEmail03())
  363.             ->returnPath($this->BaseInfo->getEmail04());
  364.         foreach($to_addresses as $ta) {
  365.             $message->addBcc($ta);
  366.         }
  367.         // HTMLテンプレートが存在する場合
  368.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  369.         if (!is_null($htmlFileName)) {
  370.             $htmlBody $this->twig->render($htmlFileName, [
  371.                 'Order' => $Order,
  372.             ]);
  373.             $message
  374.                 ->text($body)
  375.                 ->html($htmlBody);
  376.         } else {
  377.             $message->text($body);
  378.         }
  379.         $event = new EventArgs(
  380.             [
  381.                 'message' => $message,
  382.                 'Order' => $Order,
  383.                 'MailTemplate' => $MailTemplate,
  384.                 'BaseInfo' => $this->BaseInfo,
  385.             ],
  386.             null
  387.         );
  388.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ORDER);
  389.         try {
  390.             $this->mailer->send($message);
  391.         } catch (TransportExceptionInterface $e) {
  392.             log_critical($e->getMessage());
  393.         }
  394.         $MailHistory = new MailHistory();
  395.         $MailHistory->setMailSubject($message->getSubject())
  396.             ->setMailBody($message->getTextBody())
  397.             ->setOrder($Order)
  398.             ->setSendDate(new \DateTime());
  399.         // HTML用メールの設定
  400.         $htmlBody $message->getHtmlBody();
  401.         if (!empty($htmlBody)) {
  402.             $MailHistory->setMailHtmlBody($htmlBody);
  403.         }
  404.         $this->mailHistoryRepository->save($MailHistory);
  405.         log_info('受注メール送信完了');
  406.         return $message;
  407.     }
  408.     /**
  409.      * Send admin customer confirm mail.
  410.      *
  411.      * @param $Customer 会員情報
  412.      * @param string $activateUrl アクティベート用url
  413.      */
  414.     public function sendAdminCustomerConfirmMail(Customer $Customer$activateUrl)
  415.     {
  416.         log_info('仮会員登録再送メール送信開始');
  417.         /* @var $MailTemplate \Eccube\Entity\MailTemplate */
  418.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
  419.         $body $this->twig->render($MailTemplate->getFileName(), [
  420.             'BaseInfo' => $this->BaseInfo,
  421.             'Customer' => $Customer,
  422.             'activateUrl' => $activateUrl,
  423.         ]);
  424.         $to_addresses = [$this->BaseInfo->getEmail01()];
  425.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  426.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  427.         }
  428.         $message = (new Email())
  429.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  430.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  431.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  432.             ->replyTo($this->BaseInfo->getEmail03())
  433.             ->returnPath($this->BaseInfo->getEmail04());
  434.         foreach($to_addresses as $ta) {
  435.             $message->addBcc($ta);
  436.         }
  437.         // HTMLテンプレートが存在する場合
  438.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  439.         if (!is_null($htmlFileName)) {
  440.             $htmlBody $this->twig->render($htmlFileName, [
  441.                 'BaseInfo' => $this->BaseInfo,
  442.                 'Customer' => $Customer,
  443.                 'activateUrl' => $activateUrl,
  444.             ]);
  445.             $message
  446.                 ->text($body)
  447.                 ->html($htmlBody);;
  448.         } else {
  449.             $message->setBody($body);
  450.         }
  451.         $event = new EventArgs(
  452.             [
  453.                 'message' => $message,
  454.                 'Customer' => $Customer,
  455.                 'BaseInfo' => $this->BaseInfo,
  456.                 'activateUrl' => $activateUrl,
  457.             ],
  458.             null
  459.         );
  460.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM);
  461.         $count $this->mailer->send($message);
  462.         log_info('仮会員登録再送メール送信完了', ['count' => $count]);
  463.     }
  464.     /**
  465.      * Send admin order mail.
  466.      *
  467.      * @param Order $Order 受注情報
  468.      * @param $formData 入力内容
  469.      *
  470.      * @return \Email
  471.      *
  472.      * @throws \Twig_Error_Loader
  473.      * @throws \Twig_Error_Runtime
  474.      * @throws \Twig_Error_Syntax
  475.      */
  476.     public function sendAdminOrderMail(Order $Order$formData)
  477.     {
  478.         log_info('受注管理通知メール送信開始');
  479.         $Customer $Order->getCustomer();
  480.         $to_addresses = [$this->BaseInfo->getEmail01()];
  481.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  482.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  483.         }
  484.         $message = (new Email())
  485.             ->subject('['.$this->BaseInfo->getShopName().'] '.$formData['mail_subject'])
  486.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  487.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  488.             ->replyTo($this->BaseInfo->getEmail03())
  489.             ->returnPath($this->BaseInfo->getEmail04())
  490.             ->text($formData['tpl_data']);
  491.         foreach($to_addresses as $ta) {
  492.             $message->addBcc($ta);
  493.         }
  494.         $event = new EventArgs(
  495.             [
  496.                 'message' => $message,
  497.                 'Order' => $Order,
  498.                 'formData' => $formData,
  499.                 'BaseInfo' => $this->BaseInfo,
  500.             ],
  501.             null
  502.         );
  503.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ADMIN_ORDER);
  504.         try {
  505.             $this->mailer->send($message);
  506.             log_info('受注管理通知メール送信完了');
  507.         } catch (TransportExceptionInterface $e) {
  508.             log_critical($e->getMessage());
  509.         }
  510.         return $message;
  511.     }
  512.     /**
  513.      * Send password reset notification mail.
  514.      *
  515.      * @param $Customer 会員情報
  516.      * @param string $reset_url
  517.      */
  518.     public function sendPasswordResetNotificationMail(Customer $Customer$reset_url)
  519.     {
  520.         log_info('パスワード再発行メール送信開始');
  521.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_forgot_mail_template_id']);
  522.         $body $this->twig->render($MailTemplate->getFileName(), [
  523.             'BaseInfo' => $this->BaseInfo,
  524.             'Customer' => $Customer,
  525.             'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
  526.             'reset_url' => $reset_url,
  527.         ]);
  528.         $message = (new Email())
  529.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  530.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  531.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  532.             ->bcc($this->BaseInfo->getEmail01())
  533.             ->replyTo($this->BaseInfo->getEmail03())
  534.             ->returnPath($this->BaseInfo->getEmail04());
  535.         // HTMLテンプレートが存在する場合
  536.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  537.         if (!is_null($htmlFileName)) {
  538.             $htmlBody $this->twig->render($htmlFileName, [
  539.                 'BaseInfo' => $this->BaseInfo,
  540.                 'Customer' => $Customer,
  541.                 'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
  542.                 'reset_url' => $reset_url,
  543.             ]);
  544.             $message
  545.                 ->text($body)
  546.                 ->html($htmlBody);
  547.         } else {
  548.             $message->text($body);
  549.         }
  550.         $event = new EventArgs(
  551.             [
  552.                 'message' => $message,
  553.                 'Customer' => $Customer,
  554.                 'BaseInfo' => $this->BaseInfo,
  555.                 'resetUrl' => $reset_url,
  556.             ],
  557.             null
  558.         );
  559.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_PASSWORD_RESET);
  560.         try {
  561.             $this->mailer->send($message);
  562.             log_info('パスワード再発行メール送信完了');
  563.         } catch (TransportExceptionInterface $e) {
  564.             log_critical($e->getMessage());
  565.         }
  566.     }
  567.     /**
  568.      * Send password reset notification mail.
  569.      *
  570.      * @param $Customer 会員情報
  571.      * @param string $password
  572.      */
  573.     public function sendPasswordResetCompleteMail(Customer $Customer$password)
  574.     {
  575.         log_info('パスワード変更完了メール送信開始');
  576.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_reset_complete_mail_template_id']);
  577.         $body $this->twig->render($MailTemplate->getFileName(), [
  578.             'BaseInfo' => $this->BaseInfo,
  579.             'Customer' => $Customer,
  580.             'password' => $password,
  581.         ]);
  582.         $to_addresses = [$this->BaseInfo->getEmail01()];
  583.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  584.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  585.         }
  586.         $message = (new Email())
  587.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  588.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  589.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  590.             ->replyTo($this->BaseInfo->getEmail03())
  591.             ->returnPath($this->BaseInfo->getEmail04());
  592.         foreach($to_addresses as $ta) {
  593.             $message->addBcc($ta);
  594.         }
  595.         // HTMLテンプレートが存在する場合
  596.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  597.         if (!is_null($htmlFileName)) {
  598.             $htmlBody $this->twig->render($htmlFileName, [
  599.                 'BaseInfo' => $this->BaseInfo,
  600.                 'Customer' => $Customer,
  601.                 'password' => $password,
  602.             ]);
  603.             $message
  604.                 ->text($body)
  605.                 ->html($htmlBody);
  606.         } else {
  607.             $message->text($body);
  608.         }
  609.         $event = new EventArgs(
  610.             [
  611.                 'message' => $message,
  612.                 'Customer' => $Customer,
  613.                 'BaseInfo' => $this->BaseInfo,
  614.                 'password' => $password,
  615.             ],
  616.             null
  617.         );
  618.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_PASSWORD_RESET_COMPLETE);
  619.         try {
  620.             $this->mailer->send($message);
  621.             log_info('パスワード変更完了メール送信完了');
  622.         } catch (TransportExceptionInterface $e) {
  623.             log_critical($e->getMessage());
  624.         }
  625.     }
  626.     /**
  627.      * 発送通知メールを送信する.
  628.      * 発送通知メールは受注ごとに送られる
  629.      *
  630.      * @param Shipping $Shipping
  631.      *
  632.      * @throws \Twig_Error
  633.      */
  634.     public function sendShippingNotifyMail(Shipping $Shipping$deliveryNote false$pdfPath null)
  635.     {
  636.         log_info('出荷通知メール送信処理開始', ['id' => $Shipping->getId()]);
  637.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
  638.         /** @var Order $Order */
  639.         $Order $Shipping->getOrder();
  640.         $body $this->getShippingNotifyMailBody($Shipping$Order$MailTemplate->getFileName());
  641.         $Customer $Order->getCustomer();
  642.         $to_addresses = [$this->BaseInfo->getEmail01()];
  643.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  644.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  645.         }
  646.         $message = (new Email())
  647.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  648.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  649.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  650.             ->replyTo($this->BaseInfo->getEmail03())
  651.             ->returnPath($this->BaseInfo->getEmail04());
  652.         foreach($to_addresses as $ta) {
  653.             $message->addTo($this->convertRFCViolatingEmail($ta));
  654.             $message->addBcc($ta);
  655.         }
  656.         if ($deliveryNote && $pdfPath) {
  657.             $message->attachFromPath($pdfPath);
  658.         }
  659.         // HTMLテンプレートが存在する場合
  660.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  661.         if (!is_null($htmlFileName)) {
  662.             $htmlBody $this->getShippingNotifyMailBody($Shipping$Order$htmlFileNametrue);
  663.             $message
  664.                 ->text($body)
  665.                 ->html($htmlBody);
  666.         } else {
  667.             $message->text($body);
  668.         }
  669.         try {
  670.             $this->mailer->send($message);
  671.         } catch (TransportExceptionInterface $e) {
  672.             log_critical($e->getMessage());
  673.         }
  674.         $MailHistory = new MailHistory();
  675.         $MailHistory->setMailSubject($message->getSubject())
  676.                 ->setMailBody($message->getTextBody())
  677.                 ->setOrder($Order)
  678.                 ->setSendDate(new \DateTime());
  679.         // HTML用メールの設定
  680.         $htmlBody $message->getHtmlBody();
  681.         if (!empty($htmlBody)) {
  682.             $MailHistory->setMailHtmlBody($htmlBody);
  683.         }
  684.         $this->mailHistoryRepository->save($MailHistory);
  685.         log_info('出荷通知メール送信処理完了', ['id' => $Shipping->getId()]);
  686.     }
  687.     /**
  688.      * Send Temporary order mail.
  689.      *
  690.      * @param \Eccube\Entity\Order $Order 受注情報
  691.      * @return string
  692.      */
  693.     public function sendOrderTemporaryMail(\Eccube\Entity\Order $Order)
  694.     {
  695.         log_info('仮受注メール送信開始');
  696.         $MailTemplate $this->mailTemplateRepository->find(9);//仮注文受付メール
  697.         $Customer $Order->getCustomer() ? $Order->getCustomer() : $this->tokenStorage->getToken()->getUser();
  698.         if($Customer->getSchool()) {
  699.             $schoolId $Customer->getSchool()->getSchoolId();
  700.             if ($schoolId !== null) {
  701.                 $school $this->schoolRepository->find($schoolId);
  702.                 if ($school->getSchoolMeasuringDate()) {
  703.                     $measuringDate $school->getSchoolMeasuringDate()->format('Y年m月d日');
  704.                 } else {
  705.                     $measuringDate '';
  706.                 }
  707.             }
  708.         }else{
  709.             $measuringDate '';
  710.         }
  711.         $body $this->twig->render($MailTemplate->getFileName(), array(
  712.             'Order' => $Order,
  713.             'MeasuringDate' => $measuringDate,
  714.         ));
  715.         $to_addresses = [$this->BaseInfo->getEmail01()];
  716.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  717.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  718.         }
  719.         $message = (new Email())
  720.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  721.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  722.             ->replyTo($this->BaseInfo->getEmail03())
  723.             ->returnPath($this->BaseInfo->getEmail04());
  724.         foreach($to_addresses as $ta) {
  725.             $message->addTo($this->convertRFCViolatingEmail($ta));
  726.             $message->addBcc($ta);
  727.         }
  728.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  729.         if (!is_null($htmlFileName)) {
  730.             $htmlBody $this->twig->render($htmlFileName, [
  731.                 'Order' => $Order,
  732.                 'MeasuringDate' => $measuringDate,
  733.             ]);
  734.             $message
  735.                 ->text($body)
  736.                 ->html($htmlBody);
  737.         } else {
  738.             $message->text($body);
  739.         }
  740.         $event = new EventArgs(
  741.             array(
  742.                 'message' => $message,
  743.                 'Order' => $Order,
  744.                 'MailTemplate' => $MailTemplate,
  745.                 'BaseInfo' => $this->BaseInfo,
  746.             ),
  747.             null
  748.         );
  749.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ORDER);
  750.         $count $this->mailer->send($message);
  751.         if($this->session->get('is_temporary_order')){
  752.             log_info('仮注文受付メール送信完了', array('count' => $count));
  753.         }else{
  754.             log_info('仮受注メール送信完了', array('count' => $count));
  755.         }
  756.         return $body;
  757.     }
  758.     /**
  759.      * Send Reserve mail.
  760.      *
  761.      * @param \Customize\Entity\Reserve $Reserve 受注情報
  762.      * @return string
  763.      */
  764.     public function sendReserveMail(\Customize\Entity\Reserve $Reserve$mode='new'$kubun=2$Store$School)
  765.     {
  766.         log_info('予約メール送信開始');
  767.         if($mode == 'new')
  768.             $mail_temmplate_id 10;
  769.         elseif($mode == 'cancel')
  770.             $mail_temmplate_id 11;
  771.         elseif($mode == 'change')
  772.             $mail_temmplate_id 12;
  773.         $MailTemplate $this->mailTemplateRepository->find($mail_temmplate_id);//予約受付メール
  774.         $Customer $this->tokenStorage->getToken()->getUser();
  775.         $message = (new Email())
  776.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  777.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  778.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  779.             ->bcc($this->BaseInfo->getEmail01())
  780.             ->replyTo($this->BaseInfo->getEmail03())
  781.             ->returnPath($this->BaseInfo->getEmail04());
  782.         $body $this->twig->render($MailTemplate->getFileName(), array(
  783.             'Reserve' => $Reserve,
  784.             'kubun' => $kubun,
  785.             'Store' => $Store,
  786.             'School' => $School
  787.         ));
  788.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  789.         if (!is_null($htmlFileName)) {
  790.             $htmlBody $this->twig->render($htmlFileName, [
  791.                 'Reserve' => $Reserve,
  792.                 'kubun' => $kubun,
  793.                 'Store' => $Store,
  794.                 'School' => $School
  795.             ]);
  796.             $message
  797.                 ->text($body)
  798.                 ->html($htmlBody);
  799.         } else {
  800.             $message->text($body);
  801.         }
  802.         $count $this->mailer->send($message);
  803.     }
  804.     public function sendCustomMail($Shipping$template_id){
  805.         log_info('受注メール送信開始');
  806.         $Order $Shipping->getOrder();
  807.         $MailTemplate $this->mailTemplateRepository->find($template_id);
  808.         $historyUrl is_null($Order->getCustomer())
  809.         ? null
  810.         $this->container->get('router')->generate('mypage_history',['order_no' => $Order->getOrderNo()],UrlGeneratorInterface::ABSOLUTE_URL);
  811.         $body $this->twig->render($MailTemplate->getFileName(), [
  812.             'Order' => $Order,
  813.             'Shipping' => $Shipping,
  814.             'isCvsPay' => false,
  815.             'historyUrl' => $historyUrl
  816.         ]);
  817.         $Customer $Order->getCustomer();
  818.         $to_addresses = [$this->BaseInfo->getEmail01()];
  819.         if($Customer->getSchool() && $Customer->getSchool()->getSchoolEmail()) {
  820.             $to_addresses[] = $Customer->getSchool()->getSchoolEmail();
  821.         }
  822.         $message = (new Email())
  823.             ->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
  824.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  825.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  826.             ->replyTo($this->BaseInfo->getEmail03())
  827.             ->returnPath($this->BaseInfo->getEmail04());
  828.         foreach($to_addresses as $ta) {
  829.             $message->addBcc($ta);
  830.         }
  831.         // HTMLテンプレートが存在する場合
  832.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  833.         if (!is_null($htmlFileName)) {
  834.             $htmlBody $this->twig->render($htmlFileName, [
  835.                 'Order' => $Order,
  836.                 'Shipping' => $Shipping,
  837.                 'isCvsPay' => false,
  838.                 'historyUrl' => $historyUrl
  839.             ]);
  840.             $message
  841.                 ->text($body)
  842.                 ->html($htmlBody);
  843.         } else {
  844.             $message->text($body);
  845.         }
  846.         $event = new EventArgs(
  847.             [
  848.                 'message' => $message,
  849.                 'Order' => $Order,
  850.                 'MailTemplate' => $MailTemplate,
  851.                 'BaseInfo' => $this->BaseInfo,
  852.             ],
  853.             null
  854.         );
  855.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ORDER);
  856.         try {
  857.             $this->mailer->send($message);
  858.         } catch (TransportExceptionInterface $e) {
  859.             log_critical($e->getMessage());
  860.         }
  861.         return $message;
  862.     }
  863. }