src/Eccube/Service/MailService.php line 95

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 Eccube\Service;
  13. use Doctrine\ORM\NonUniqueResultException;
  14. use Eccube\Common\EccubeConfig;
  15. use Eccube\Entity\BaseInfo;
  16. use Eccube\Entity\Customer;
  17. use Eccube\Entity\MailHistory;
  18. use Eccube\Entity\MailTemplate;
  19. use Eccube\Entity\Order;
  20. use Eccube\Entity\OrderItem;
  21. use Eccube\Entity\Shipping;
  22. use Eccube\Event\EccubeEvents;
  23. use Eccube\Event\EventArgs;
  24. use Eccube\Repository\BaseInfoRepository;
  25. use Eccube\Repository\MailHistoryRepository;
  26. use Eccube\Repository\MailTemplateRepository;
  27. use Symfony\Component\DependencyInjection\ContainerInterface;
  28. use Symfony\Component\EventDispatcher\EventDispatcher;
  29. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  30. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  31. use Symfony\Component\Mailer\MailerInterface;
  32. use Symfony\Component\Mime\Address;
  33. use Symfony\Component\Mime\Email;
  34. use Twig\Error\LoaderError;
  35. use Twig\Error\RuntimeError;
  36. use Twig\Error\SyntaxError;
  37. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  38. class MailService
  39. {
  40.     /**
  41.      * @var MailerInterface
  42.      */
  43.     protected $mailer;
  44.     /**
  45.      * @var MailTemplateRepository
  46.      */
  47.     protected $mailTemplateRepository;
  48.     /**
  49.      * @var MailHistoryRepository
  50.      */
  51.     protected $mailHistoryRepository;
  52.     /**
  53.      * @var EventDispatcher
  54.      */
  55.     protected $eventDispatcher;
  56.     /**
  57.      * @var BaseInfo
  58.      */
  59.     protected $BaseInfo;
  60.     /**
  61.      * @var EccubeConfig
  62.      */
  63.     protected $eccubeConfig;
  64.     /**
  65.      * @var \Twig\Environment
  66.      */
  67.     protected $twig;
  68.     /** @var ContainerInterface */
  69.     protected $container;
  70.     /**
  71.      * MailService constructor.
  72.      *
  73.      * @param MailerInterface $mailer
  74.      * @param MailTemplateRepository $mailTemplateRepository
  75.      * @param MailHistoryRepository $mailHistoryRepository
  76.      * @param BaseInfoRepository $baseInfoRepository
  77.      * @param EventDispatcherInterface $eventDispatcher
  78.      * @param \Twig\Environment $twig
  79.      * @param EccubeConfig $eccubeConfig
  80.      * @param ContainerInterface $container
  81.      */
  82.     public function __construct(
  83.         MailerInterface $mailer,
  84.         MailTemplateRepository $mailTemplateRepository,
  85.         MailHistoryRepository $mailHistoryRepository,
  86.         BaseInfoRepository $baseInfoRepository,
  87.         EventDispatcherInterface $eventDispatcher,
  88.         \Twig\Environment $twig,
  89.         EccubeConfig $eccubeConfig,
  90.         ContainerInterface $container,
  91.         SessionInterface $session
  92.     ) {
  93.         $this->mailer $mailer;
  94.         $this->mailTemplateRepository $mailTemplateRepository;
  95.         $this->mailHistoryRepository $mailHistoryRepository;
  96.         $this->BaseInfo $baseInfoRepository->get();
  97.         $this->eventDispatcher $eventDispatcher;
  98.         $this->eccubeConfig $eccubeConfig;
  99.         $this->twig $twig;
  100.         $this->container $container;
  101.         $this->session $session;
  102.     }
  103.     /**
  104.      * メールアカウント
  105.      * getEmail01() 送信元
  106.      * getEmail02() 問い合わせ専用
  107.      * getEmail03() 返信先(From, ReplyTo) 
  108.      * getEmail04() 管理者
  109.      * getEmail05() コールセンター
  110.      * getEmail06() 工場専用
  111.      */
  112.     /**
  113.      * Send customer confirm mail.
  114.      *
  115.      * @param $Customer 会員情報
  116.      * @param string $activateUrl アクティベート用url
  117.      */
  118.     public function sendCustomerConfirmMail(Customer $Customer$activateUrl)
  119.     {
  120.         log_info('仮会員登録メール送信開始');
  121.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
  122.         $body $this->twig->render($MailTemplate->getFileName(), [
  123.             'Customer' => $Customer,
  124.             'BaseInfo' => $this->BaseInfo,
  125.             'activateUrl' => $activateUrl,
  126.         ]);
  127.         $message = (new Email())
  128.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  129.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  130.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  131.             // ->bcc($this->BaseInfo->getEmail04())
  132.             ->replyTo($this->BaseInfo->getEmail03())
  133.             ->returnPath($this->BaseInfo->getEmail04());
  134.         // HTMLテンプレートが存在する場合
  135.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  136.         if (!is_null($htmlFileName)) {
  137.             $htmlBody $this->twig->render($htmlFileName, [
  138.                 'Customer' => $Customer,
  139.                 'BaseInfo' => $this->BaseInfo,
  140.                 'activateUrl' => $activateUrl,
  141.             ]);
  142.             $message
  143.                 ->text($body)
  144.                 ->html($htmlBody);
  145.         } else {
  146.             $message->text($body);
  147.         }
  148.         $event = new EventArgs(
  149.             [
  150.                 'message' => $message,
  151.                 'Customer' => $Customer,
  152.                 'BaseInfo' => $this->BaseInfo,
  153.                 'activateUrl' => $activateUrl,
  154.             ],
  155.             null
  156.         );
  157.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_CONFIRM);
  158.         // 代理運用フラグが立っている場合はメールを送信しない
  159.         if ($Customer->getAgentOperationFlag()) {
  160.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  161.             return;
  162.         }
  163.         try {
  164.             $this->mailer->send($message);
  165.             log_info('仮会員登録メール送信完了');
  166.         } catch (TransportExceptionInterface $e) {
  167.             log_critical($e->getMessage());
  168.         }
  169.     }
  170.     /**
  171.      * Send customer change email confirm mail.
  172.      *
  173.      * @param $Customer 会員情報
  174.      * @param string $activateUrl アクティベート用url
  175.      * @param string $preEmail 変更するメールアドレス
  176.      */
  177.     public function sendChangeMailConfirmMail(Customer $Customer$activateUrl$userData)
  178.     {
  179.         log_info('メールアドレス変更認証メール送信開始');
  180.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_change_email_confirm_mail_template_id']);
  181.         $body $this->twig->render($MailTemplate->getFileName(), [
  182.             'Customer' => $Customer,
  183.             'BaseInfo' => $this->BaseInfo,
  184.             'activateUrl' => $activateUrl,
  185.             'userAgent' => $userData['userAgent'],
  186.             'ipAddress' => $userData['ipAddress'],
  187.         ]);
  188.         $message = (new Email())
  189.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  190.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  191.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  192.             // ->bcc($this->BaseInfo->getEmail04())
  193.             ->replyTo($this->BaseInfo->getEmail03())
  194.             ->returnPath($this->BaseInfo->getEmail04());
  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.                 'activateUrl' => $activateUrl,
  202.                 'userAgent' => $userData['userAgent'],
  203.                 'ipAddress' => $userData['ipAddress'],
  204.             ]);
  205.             $message
  206.                 ->text($body)
  207.                 ->html($htmlBody);
  208.         } else {
  209.             $message->text($body);
  210.         }
  211.         // $event = new EventArgs(
  212.         //     [
  213.         //         'message' => $message,
  214.         //         'Customer' => $Customer,
  215.         //         'BaseInfo' => $this->BaseInfo,
  216.         //         'activateUrl' => $activateUrl,
  217.         //     ],
  218.         //     null
  219.         // );
  220.         // $this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_CONFIRM);
  221.         // 代理運用フラグが立っている場合はメールを送信しない
  222.         if ($Customer->getAgentOperationFlag()) {
  223.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  224.             return;
  225.         }
  226.         try {
  227.             $this->mailer->send($message);
  228.             log_info('仮会員登録メール送信完了');
  229.         } catch (TransportExceptionInterface $e) {
  230.             log_critical($e->getMessage());
  231.         }
  232.     }
  233.     /**
  234.      * Send customer change email complete mail.
  235.      *
  236.      * @param $Customer 会員情報
  237.      * @param string $prevEmail 変更前のメールアドレス
  238.      * @param string $changedEmail 変更後のメールアドレス
  239.      */
  240.     public function sendChangeMailCompleteMail(Customer $Customer$prevEmail$changedEmail)
  241.     {
  242.         log_info('メールアドレス変更完了メール送信開始');
  243.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_complete_change_customer_email_mail_template_id']);
  244.         $body $this->twig->render($MailTemplate->getFileName(), [
  245.             'Customer' => $Customer,
  246.             'BaseInfo' => $this->BaseInfo,
  247.             'PrevEmail' => $prevEmail,
  248.             'ChangedEmail' => $changedEmail,
  249.         ]);
  250.         $message = (new Email())
  251.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  252.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  253.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  254.             // ->bcc($this->BaseInfo->getEmail04())
  255.             ->replyTo($this->BaseInfo->getEmail03())
  256.             ->returnPath($this->BaseInfo->getEmail04());
  257.         // HTMLテンプレートが存在する場合
  258.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  259.         if (!is_null($htmlFileName)) {
  260.             $htmlBody $this->twig->render($htmlFileName, [
  261.                 'Customer' => $Customer,
  262.                 'BaseInfo' => $this->BaseInfo,
  263.                 'PrevEmail' => $prevEmail,
  264.                 'ChangedEmail' => $changedEmail,
  265.             ]);
  266.             $message
  267.                 ->text($body)
  268.                 ->html($htmlBody);
  269.         } else {
  270.             $message->text($body);
  271.         }
  272.         // 代理運用フラグが立っている場合はメールを送信しない
  273.         if ($Customer->getAgentOperationFlag()) {
  274.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  275.             return;
  276.         }
  277.         try {
  278.             $this->mailer->send($message);
  279.             log_info('メールアドレス変更完了メール送信完了');
  280.         } catch (TransportExceptionInterface $e) {
  281.             log_critical($e->getMessage());
  282.         }
  283.     }
  284.     /**
  285.      * Send customer complete mail.
  286.      *
  287.      * @param $Customer 会員情報
  288.      */
  289.     public function sendCustomerCompleteMail(Customer $Customer)
  290.     {
  291.         log_info('会員登録完了メール送信開始');
  292.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_complete_mail_template_id']);
  293.         $body $this->twig->render($MailTemplate->getFileName(), [
  294.             'Customer' => $Customer,
  295.             'BaseInfo' => $this->BaseInfo,
  296.         ]);
  297.         $message = (new Email())
  298.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  299.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  300.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  301.             // ->bcc($this->BaseInfo->getEmail04())
  302.             ->replyTo($this->BaseInfo->getEmail03())
  303.             ->returnPath($this->BaseInfo->getEmail04());
  304.         // HTMLテンプレートが存在する場合
  305.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  306.         if (!is_null($htmlFileName)) {
  307.             $htmlBody $this->twig->render($htmlFileName, [
  308.                 'Customer' => $Customer,
  309.                 'BaseInfo' => $this->BaseInfo,
  310.             ]);
  311.             $message
  312.                 ->text($body)
  313.                 ->html($htmlBody);
  314.         } else {
  315.             $message->text($body);
  316.         }
  317.         $event = new EventArgs(
  318.             [
  319.                 'message' => $message,
  320.                 'Customer' => $Customer,
  321.                 'BaseInfo' => $this->BaseInfo,
  322.             ],
  323.             null
  324.         );
  325.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_COMPLETE);
  326.         // 代理運用フラグが立っている場合はメールを送信しない
  327.         if ($Customer->getAgentOperationFlag()) {
  328.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  329.             return;
  330.         }
  331.         try {
  332.             $this->mailer->send($message);
  333.             log_info('会員登録完了メール送信完了');
  334.         } catch (TransportExceptionInterface $e) {
  335.             log_critical($e->getMessage());
  336.         }
  337.     }
  338.     /**
  339.      * Send withdraw mail.
  340.      *
  341.      * @param $Customer Customer
  342.      * @param $email string
  343.      */
  344.     public function sendCustomerWithdrawMail(Customer $Customerstring $email)
  345.     {
  346.         log_info('退会手続き完了メール送信開始');
  347.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_customer_withdraw_mail_template_id']);
  348.         $body $this->twig->render($MailTemplate->getFileName(), [
  349.             'Customer' => $Customer,
  350.             'BaseInfo' => $this->BaseInfo,
  351.         ]);
  352.         // 複数アドレスの設定
  353.         $addresses = [
  354.             $this->convertRFCViolatingEmail($email),
  355.             // $this->BaseInfo->getEmail04(),
  356.             // 他のアドレスも追加可能
  357.         ];
  358.         $message = (new Email())
  359.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  360.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()));
  361.         foreach ($addresses as $address) {
  362.             // 各アドレスをメールの送信先として追加する
  363.             $message->addTo($address);
  364.         }
  365.         $message
  366.             // ->bcc($this->BaseInfo->getEmail04())
  367.             ->replyTo($this->BaseInfo->getEmail03())
  368.             ->returnPath($this->BaseInfo->getEmail04());
  369.         // HTMLテンプレートが存在する場合
  370.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  371.         if (!is_null($htmlFileName)) {
  372.             $htmlBody $this->twig->render($htmlFileName, [
  373.                 'Customer' => $Customer,
  374.                 'BaseInfo' => $this->BaseInfo,
  375.             ]);
  376.             $message
  377.                 ->text($body)
  378.                 ->html($htmlBody);
  379.         } else {
  380.             $message->text($body);
  381.         }
  382.         $event = new EventArgs(
  383.             [
  384.                 'message' => $message,
  385.                 'Customer' => $Customer,
  386.                 'BaseInfo' => $this->BaseInfo,
  387.                 'email' => $email,
  388.             ],
  389.             null
  390.         );
  391.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CUSTOMER_WITHDRAW);
  392.         // 代理運用フラグが立っている場合はメールを送信しない
  393.         if ($Customer->getAgentOperationFlag()) {
  394.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  395.             return;
  396.         }
  397.         try {
  398.             $this->mailer->send($message);
  399.             log_info('退会手続き完了メール送信完了');
  400.         } catch (TransportExceptionInterface $e) {
  401.             log_critical($e->getMessage());
  402.         }
  403.     }
  404.     /**
  405.      * Send contact mail.
  406.      *
  407.      * @param $formData お問い合わせ内容
  408.      */
  409.     public function sendContactMail($formData)
  410.     {
  411.         log_info('お問い合わせ受付メール送信開始');
  412.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_contact_mail_template_id']);
  413.         $body $this->twig->render($MailTemplate->getFileName(), [
  414.             'data' => $formData,
  415.             'BaseInfo' => $this->BaseInfo,
  416.         ]);
  417.         // 複数アドレスの設定
  418.         $addresses = [
  419.             $this->convertRFCViolatingEmail($formData['email']),
  420.             $this->BaseInfo->getEmail02(),
  421.             // 他のアドレスも追加可能
  422.         ];
  423.         $message = (new Email())
  424.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  425.             ->from(new Address($this->BaseInfo->getEmail02(), $this->BaseInfo->getShopName()));
  426.         foreach ($addresses as $address) {
  427.             // 各アドレスをメールの送信先として追加する
  428.             $message->addTo($address);
  429.         }
  430.         $message
  431.             ->bcc($this->BaseInfo->getEmail04())
  432.             ->replyTo($this->BaseInfo->getEmail02())
  433.             ->returnPath($this->BaseInfo->getEmail04())
  434.             ->returnPath($this->BaseInfo->getEmail04());
  435.         // 問い合わせ者にメール送信
  436.         // $message = (new Email())
  437.         //     ->subject('[' . $this->BaseInfo->getShopName() . '] ' . $MailTemplate->getMailSubject())
  438.         //     ->from(new Address($this->BaseInfo->getEmail02(), $this->BaseInfo->getShopName()))
  439.         //     ->to($this->convertRFCViolatingEmail($formData['email']))
  440.         //     ->bcc($this->BaseInfo->getEmail02())
  441.         //     ->replyTo($this->BaseInfo->getEmail02())
  442.         //     ->returnPath($this->BaseInfo->getEmail04());
  443.         // HTMLテンプレートが存在する場合
  444.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  445.         if (!is_null($htmlFileName)) {
  446.             $htmlBody $this->twig->render($htmlFileName, [
  447.                 'data' => $formData,
  448.                 'BaseInfo' => $this->BaseInfo,
  449.             ]);
  450.             $message
  451.                 ->text($body)
  452.                 ->html($htmlBody);
  453.         } else {
  454.             $message->text($body);
  455.         }
  456.         $event = new EventArgs(
  457.             [
  458.                 'message' => $message,
  459.                 'formData' => $formData,
  460.                 'BaseInfo' => $this->BaseInfo,
  461.             ],
  462.             null
  463.         );
  464.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_CONTACT);
  465.         try {
  466.             $this->mailer->send($message);
  467.             log_info('お問い合わせ受付メール送信完了');
  468.         } catch (TransportExceptionInterface $e) {
  469.             log_critical($e->getMessage());
  470.         }
  471.     }
  472.     /**
  473.      * Send order mail.
  474.      *
  475.      * @param \Eccube\Entity\Order $Order 受注情報
  476.      *
  477.      * @return Email
  478.      */
  479.     public function sendOrderMail(Order $Order)
  480.     {
  481.         log_info('受注メール送信開始');
  482.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_mail_template_id']);
  483.         $body $this->twig->render($MailTemplate->getFileName(), [
  484.             'Order' => $Order,
  485.         ]);
  486.         $message = (new Email())
  487.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  488.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  489.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  490.             // ->bcc($this->BaseInfo->getEmail04())
  491.             ->replyTo($this->BaseInfo->getEmail03())
  492.             ->returnPath($this->BaseInfo->getEmail04());
  493.         // HTMLテンプレートが存在する場合
  494.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  495.         if (!is_null($htmlFileName)) {
  496.             $htmlBody $this->twig->render($htmlFileName, [
  497.                 'Order' => $Order,
  498.             ]);
  499.             $message
  500.                 ->text($body)
  501.                 ->html($htmlBody);
  502.         } else {
  503.             $message->text($body);
  504.         }
  505.         $event = new EventArgs(
  506.             [
  507.                 'message' => $message,
  508.                 'Order' => $Order,
  509.                 'MailTemplate' => $MailTemplate,
  510.                 'BaseInfo' => $this->BaseInfo,
  511.             ],
  512.             null
  513.         );
  514.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ORDER);
  515.         // 代理運用フラグが立っている場合はメールを送信しない
  516.         $Customer $Order->getCustomer();
  517.         if ($Customer->getAgentOperationFlag()) {
  518.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  519.             return;
  520.         }
  521.         try {
  522.             $this->mailer->send($message);
  523.         } catch (TransportExceptionInterface $e) {
  524.             log_critical($e->getMessage());
  525.         }
  526.         $MailHistory = new MailHistory();
  527.         $MailHistory->setMailSubject($message->getSubject())
  528.             ->setMailBody($message->getTextBody())
  529.             ->setOrder($Order)
  530.             ->setSendDate(new \DateTime());
  531.         // HTML用メールの設定
  532.         $htmlBody $message->getHtmlBody();
  533.         if (!empty($htmlBody)) {
  534.             $MailHistory->setMailHtmlBody($htmlBody);
  535.         }
  536.         $this->mailHistoryRepository->save($MailHistory);
  537.         log_info('受注メール送信完了');
  538.         return $message;
  539.     }
  540.     /**
  541.      * Send admin customer confirm mail.
  542.      *
  543.      * @param $Customer 会員情報
  544.      * @param string $activateUrl アクティベート用url
  545.      */
  546.     public function sendAdminCustomerConfirmMail(Customer $Customer$activateUrl)
  547.     {
  548.         log_info('仮会員登録再送メール送信開始');
  549.         /* @var $MailTemplate \Eccube\Entity\MailTemplate */
  550.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
  551.         $body $this->twig->render($MailTemplate->getFileName(), [
  552.             'BaseInfo' => $this->BaseInfo,
  553.             'Customer' => $Customer,
  554.             'activateUrl' => $activateUrl,
  555.         ]);
  556.         $message = (new Email())
  557.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  558.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  559.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  560.             // ->bcc($this->BaseInfo->getEmail04())
  561.             ->replyTo($this->BaseInfo->getEmail03())
  562.             ->returnPath($this->BaseInfo->getEmail04());
  563.         // HTMLテンプレートが存在する場合
  564.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  565.         if (!is_null($htmlFileName)) {
  566.             $htmlBody $this->twig->render($htmlFileName, [
  567.                 'BaseInfo' => $this->BaseInfo,
  568.                 'Customer' => $Customer,
  569.                 'activateUrl' => $activateUrl,
  570.             ]);
  571.             $message
  572.                 ->text($body)
  573.                 ->html($htmlBody);
  574.         } else {
  575.             $message->text($body);
  576.         }
  577.         $event = new EventArgs(
  578.             [
  579.                 'message' => $message,
  580.                 'Customer' => $Customer,
  581.                 'BaseInfo' => $this->BaseInfo,
  582.                 'activateUrl' => $activateUrl,
  583.             ],
  584.             null
  585.         );
  586.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM);
  587.         // 代理運用フラグが立っている場合はメールを送信しない
  588.         if ($Customer->getAgentOperationFlag()) {
  589.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  590.             return;
  591.         }
  592.         try {
  593.             $this->mailer->send($message);
  594.             log_info('仮会員登録再送メール送信完了');
  595.         } catch (TransportExceptionInterface $e) {
  596.             log_critical($e->getMessage());
  597.         }
  598.     }
  599.     /**
  600.      * Send admin order mail.
  601.      *
  602.      * @param Order $Order 受注情報
  603.      * @param $formData 入力内容
  604.      *
  605.      * @return Email
  606.      *
  607.      * @throws \Twig_Error_Loader
  608.      * @throws \Twig_Error_Runtime
  609.      * @throws \Twig_Error_Syntax
  610.      */
  611.     public function sendAdminOrderMail(Order $Order$formData)
  612.     {
  613.         log_info('受注管理通知メール送信開始');
  614.         $message = (new Email())
  615.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $formData['mail_subject'])
  616.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  617.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  618.             ->bcc($this->BaseInfo->getEmail04())
  619.             ->replyTo($this->BaseInfo->getEmail03())
  620.             ->returnPath($this->BaseInfo->getEmail04())
  621.             ->text($formData['tpl_data']);
  622.         $event = new EventArgs(
  623.             [
  624.                 'message' => $message,
  625.                 'Order' => $Order,
  626.                 'formData' => $formData,
  627.                 'BaseInfo' => $this->BaseInfo,
  628.             ],
  629.             null
  630.         );
  631.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_ADMIN_ORDER);
  632.         // 代理運用フラグが立っている場合はメールを送信しない
  633.         $Customer $Order->getCustomer();
  634.         if ($Customer->getAgentOperationFlag()) {
  635.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  636.             return;
  637.         }
  638.         try {
  639.             $this->mailer->send($message);
  640.             log_info('受注管理通知メール送信完了');
  641.         } catch (TransportExceptionInterface $e) {
  642.             log_critical($e->getMessage());
  643.         }
  644.         return $message;
  645.     }
  646.     /**
  647.      * Send password reset notification mail.
  648.      *
  649.      * @param $Customer 会員情報
  650.      * @param string $reset_url
  651.      */
  652.     public function sendPasswordResetNotificationMail(Customer $Customer$reset_url)
  653.     {
  654.         log_info('パスワード再発行メール送信開始');
  655.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_forgot_mail_template_id']);
  656.         $body $this->twig->render($MailTemplate->getFileName(), [
  657.             'BaseInfo' => $this->BaseInfo,
  658.             'Customer' => $Customer,
  659.             'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
  660.             'reset_url' => $reset_url,
  661.         ]);
  662.         $message = (new Email())
  663.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  664.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  665.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  666.             // ->bcc($this->BaseInfo->getEmail04())
  667.             ->replyTo($this->BaseInfo->getEmail03())
  668.             ->returnPath($this->BaseInfo->getEmail04());
  669.         // HTMLテンプレートが存在する場合
  670.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  671.         if (!is_null($htmlFileName)) {
  672.             $htmlBody $this->twig->render($htmlFileName, [
  673.                 'BaseInfo' => $this->BaseInfo,
  674.                 'Customer' => $Customer,
  675.                 'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
  676.                 'reset_url' => $reset_url,
  677.             ]);
  678.             $message
  679.                 ->text($body)
  680.                 ->html($htmlBody);
  681.         } else {
  682.             $message->text($body);
  683.         }
  684.         $event = new EventArgs(
  685.             [
  686.                 'message' => $message,
  687.                 'Customer' => $Customer,
  688.                 'BaseInfo' => $this->BaseInfo,
  689.                 'resetUrl' => $reset_url,
  690.             ],
  691.             null
  692.         );
  693.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_PASSWORD_RESET);
  694.         // 代理運用フラグが立っている場合はメールを送信しない
  695.         if ($Customer->getAgentOperationFlag()) {
  696.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  697.             return;
  698.         }
  699.         try {
  700.             $this->mailer->send($message);
  701.             log_info('パスワード再発行メール送信完了');
  702.         } catch (TransportExceptionInterface $e) {
  703.             log_critical($e->getMessage());
  704.         }
  705.     }
  706.     /**
  707.      * Send password reset notification mail.
  708.      *
  709.      * @param $Customer 会員情報
  710.      * @param string $password
  711.      */
  712.     public function sendPasswordResetCompleteMail(Customer $Customer$password)
  713.     {
  714.         log_info('パスワード変更完了メール送信開始');
  715.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_reset_complete_mail_template_id']);
  716.         $body $this->twig->render($MailTemplate->getFileName(), [
  717.             'BaseInfo' => $this->BaseInfo,
  718.             'Customer' => $Customer,
  719.             'password' => $password,
  720.         ]);
  721.         $message = (new Email())
  722.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  723.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  724.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  725.             // ->bcc($this->BaseInfo->getEmail04())
  726.             ->replyTo($this->BaseInfo->getEmail03())
  727.             ->returnPath($this->BaseInfo->getEmail04());
  728.         // HTMLテンプレートが存在する場合
  729.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  730.         if (!is_null($htmlFileName)) {
  731.             $htmlBody $this->twig->render($htmlFileName, [
  732.                 'BaseInfo' => $this->BaseInfo,
  733.                 'Customer' => $Customer,
  734.                 'password' => $password,
  735.             ]);
  736.             $message
  737.                 ->text($body)
  738.                 ->html($htmlBody);
  739.         } else {
  740.             $message->text($body);
  741.         }
  742.         $event = new EventArgs(
  743.             [
  744.                 'message' => $message,
  745.                 'Customer' => $Customer,
  746.                 'BaseInfo' => $this->BaseInfo,
  747.                 'password' => $password,
  748.             ],
  749.             null
  750.         );
  751.         $this->eventDispatcher->dispatch($eventEccubeEvents::MAIL_PASSWORD_RESET_COMPLETE);
  752.         // 代理運用フラグが立っている場合はメールを送信しない
  753.         if ($Customer->getAgentOperationFlag()) {
  754.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  755.             return;
  756.         }
  757.         try {
  758.             $this->mailer->send($message);
  759.             log_info('パスワード変更完了メール送信完了');
  760.         } catch (TransportExceptionInterface $e) {
  761.             log_critical($e->getMessage());
  762.         }
  763.     }
  764.     /**
  765.      * 発送通知メールを送信する.
  766.      * 発送通知メールは受注ごとに送られる
  767.      *
  768.      * @param Shipping $Shipping
  769.      *
  770.      * @throws \Twig_Error
  771.      */
  772.     public function sendShippingNotifyMail(Shipping $Shipping)
  773.     {
  774.         log_info('出荷通知メール送信処理開始', ['id' => $Shipping->getId()]);
  775.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
  776.         /** @var Order $Order */
  777.         $Order $Shipping->getOrder();
  778.         $body $this->getShippingNotifyMailBody($Shipping$Order$MailTemplate->getFileName());
  779.         $message = (new Email())
  780.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  781.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  782.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  783.             // ->bcc($this->BaseInfo->getEmail04())
  784.             ->replyTo($this->BaseInfo->getEmail03())
  785.             ->returnPath($this->BaseInfo->getEmail04());
  786.         // HTMLテンプレートが存在する場合
  787.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  788.         if (!is_null($htmlFileName)) {
  789.             $htmlBody $this->getShippingNotifyMailBody($Shipping$Order$htmlFileNametrue);
  790.             $message
  791.                 ->text($body)
  792.                 ->html($htmlBody);
  793.         } else {
  794.             $message->text($body);
  795.         }
  796.         // 代理運用フラグが立っている場合はメールを送信しない
  797.         $Customer $Order->getCustomer();
  798.         if ($Customer->getAgentOperationFlag()) {
  799.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  800.             return;
  801.         }
  802.         try {
  803.             $this->mailer->send($message);
  804.         } catch (TransportExceptionInterface $e) {
  805.             log_critical($e->getMessage());
  806.         }
  807.         $MailHistory = new MailHistory();
  808.         $MailHistory->setMailSubject($message->getSubject())
  809.             ->setMailBody($message->getTextBody())
  810.             ->setOrder($Order)
  811.             ->setSendDate(new \DateTime());
  812.         // HTML用メールの設定
  813.         $htmlBody $message->getHtmlBody();
  814.         if (!empty($htmlBody)) {
  815.             $MailHistory->setMailHtmlBody($htmlBody);
  816.         }
  817.         $this->mailHistoryRepository->save($MailHistory);
  818.         log_info('出荷通知メール送信処理完了', ['id' => $Shipping->getId()]);
  819.     }
  820.     /**
  821.      * @param Shipping $Shipping
  822.      * @param Order $Order
  823.      * @param string|null $templateName
  824.      * @param boolean $is_html
  825.      *
  826.      * @return string
  827.      *
  828.      * @throws \Twig_Error
  829.      */
  830.     public function getShippingNotifyMailBody(Shipping $ShippingOrder $Order$templateName null$is_html false)
  831.     {
  832.         $ShippingItems array_filter($Shipping->getOrderItems()->toArray(), function (OrderItem $OrderItem) use ($Order) {
  833.             return $OrderItem->getOrderId() === $Order->getId();
  834.         });
  835.         if (is_null($templateName)) {
  836.             /** @var MailTemplate $MailTemplate */
  837.             $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
  838.             $fileName $MailTemplate->getFileName();
  839.         } else {
  840.             $fileName $templateName;
  841.         }
  842.         if ($is_html) {
  843.             $htmlFileName $this->getHtmlTemplate($fileName);
  844.             $fileName = !is_null($htmlFileName) ? $htmlFileName $fileName;
  845.         }
  846.         return $this->twig->render($fileName, [
  847.             'Shipping' => $Shipping,
  848.             'ShippingItems' => $ShippingItems,
  849.             'Order' => $Order,
  850.         ]);
  851.     }
  852.     /**
  853.      * 会員情報変更時にメール通知
  854.      *
  855.      * @param Customer $Customer
  856.      * @param array $userData
  857.      *  - userAgent
  858.      *  - ipAddress
  859.      *  - preEmail
  860.      * @param string $eventName
  861.      *
  862.      * @return void
  863.      *
  864.      * @throws LoaderError
  865.      * @throws NonUniqueResultException
  866.      * @throws RuntimeError
  867.      * @throws SyntaxError
  868.      */
  869.     //===============
  870.     //カスタマイズ
  871.     //会員情報変更時は、変更前と変更後の情報を追加
  872.     //===============
  873.     public function sendCustomerChangeNotifyMail(Customer $Customer, array $userDatastring $eventName)
  874.     {
  875.         log_info('会員情報変更通知メール送信処理開始');
  876.         log_info($eventName);
  877.         // 変更前のデータをセッションから取得
  878.         $originalData $this->session->get('original_customer_data');
  879.         // メールテンプレートの取得 IDでの取得は現行環境での差異があるため
  880.         $tpl_name 'Mail/customer_change_notify.twig';
  881.         $MailTemplate $this->mailTemplateRepository->createQueryBuilder('mt')
  882.             ->where('mt.file_name = :file_name')
  883.             ->setParameter('file_name'$tpl_name)
  884.             ->getQuery()
  885.             ->getOneOrNullResult();
  886.         $body $this->twig->render($MailTemplate->getFileName(), [
  887.             'BaseInfo' => $this->BaseInfo,
  888.             'Customer' => $Customer,
  889.             'userAgent' => $userData['userAgent'],
  890.             'eventName' => $eventName,
  891.             'ipAddress' => $userData['ipAddress'],
  892.             'OriginalData' => $originalData// 変更前のデータをテンプレートに渡す
  893.         ]);
  894.         $message = (new Email())
  895.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  896.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  897.             ->to($this->convertRFCViolatingEmail($Customer->getEmail()))
  898.             // ->bcc($this->BaseInfo->getEmail04())
  899.             ->replyTo($this->BaseInfo->getEmail03())
  900.             ->returnPath($this->BaseInfo->getEmail04());
  901.         // HTMLテンプレートが存在する場合
  902.         $htmlFileName $this->getHtmlTemplate($MailTemplate->getFileName());
  903.         if (!is_null($htmlFileName)) {
  904.             $htmlBody $this->twig->render($htmlFileName, [
  905.                 'BaseInfo' => $this->BaseInfo,
  906.                 'Customer' => $Customer,
  907.                 'userAgent' => $userData['userAgent'],
  908.                 'eventName' => $eventName,
  909.                 'ipAddress' => $userData['ipAddress'],
  910.                 'OriginalData' => $originalData// 変更前のデータをテンプレートに渡す
  911.             ]);
  912.             $message
  913.                 ->text($body)
  914.                 ->html($htmlBody);
  915.         } else {
  916.             $message->text($body);
  917.         }
  918.         // 代理運用フラグが立っている場合はメールを送信しない
  919.         if ($Customer->getAgentOperationFlag()) {
  920.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  921.             return;
  922.         }
  923.         try {
  924.             $this->mailer->send($message);
  925.         } catch (TransportExceptionInterface $e) {
  926.             log_critical($e->getMessage());
  927.         }
  928.         // メールアドレスの変更があった場合、変更前のメールアドレスにも送信
  929.         if (isset($userData['preEmail']) && $Customer->getEmail() != $userData['preEmail']) {
  930.             $message->to($this->convertRFCViolatingEmail($userData['preEmail']));
  931.             // メール送信
  932.             try {
  933.                 $this->mailer->send($message);
  934.             } catch (TransportExceptionInterface $e) {
  935.                 log_critical($e->getMessage());
  936.             }
  937.         }
  938.         log_info('会員情報変更通知メール送信処理完了');
  939.     }
  940.     /**
  941.      * [getHtmlTemplate description]
  942.      *
  943.      * @param  string $templateName  プレーンテキストメールのファイル名
  944.      *
  945.      * @return string|null  存在する場合はファイル名を返す
  946.      */
  947.     public function getHtmlTemplate($templateName)
  948.     {
  949.         // メールテンプレート名からHTMLメール用テンプレート名を生成
  950.         $fileName explode('.'$templateName);
  951.         $suffix '.html';
  952.         $htmlFileName $fileName[0] . $suffix '.' $fileName[1];
  953.         // HTMLメール用テンプレートの存在チェック
  954.         if ($this->twig->getLoader()->exists($htmlFileName)) {
  955.             return $htmlFileName;
  956.         } else {
  957.             return null;
  958.         }
  959.     }
  960.     /**
  961.      * RFC違反のメールの local part を "" で囲む.
  962.      *
  963.      * パラメータ eccube_rfc_email_check == true の場合は変換しない
  964.      *
  965.      * @param string $email
  966.      *
  967.      * @return Address
  968.      */
  969.     public function convertRFCViolatingEmail(string $email): Address
  970.     {
  971.         if ($this->container->getParameter('eccube_rfc_email_check')) {
  972.             return new Address($email);
  973.         }
  974.         // see https://blog.everqueue.com/chiba/2009/03/22/163/
  975.         $wsp '[\x20\x09]';
  976.         $vchar '[\x21-\x7e]';
  977.         $quoted_pair "\\\\(?:$vchar|$wsp)";
  978.         $qtext '[\x21\x23-\x5b\x5d-\x7e]';
  979.         $qcontent "(?:$qtext|$quoted_pair)";
  980.         $quoted_string "\"$qcontent*\"";
  981.         $atext '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]';
  982.         $dot_atom "$atext+(?:[.]$atext+)*";
  983.         $local_part "(?:$dot_atom|$quoted_string)";
  984.         $domain $dot_atom;
  985.         $addr_spec "{$local_part}[@]$domain";
  986.         $dot_atom_loose "$atext+(?:[.]|$atext)*";
  987.         $local_part_loose "(?:$dot_atom_loose|$quoted_string)";
  988.         $addr_spec_loose "{$local_part_loose}[@]$domain";
  989.         $regexp "/\A{$addr_spec}\z/";
  990.         if (!preg_match($regexp$email)) {
  991.             $email preg_replace('/^(.*)@(.*)$/''"$1"@$2'$email);
  992.         }
  993.         return new Address($email);
  994.     }
  995.     /**
  996.      * キャンセル通知メールを会員向けに送信する.
  997.      *
  998.      * @param Order $Order
  999.      *
  1000.      * @throws \Twig_Error
  1001.      */
  1002.     public function sendCancelNotifyMail(Order $Order)
  1003.     {
  1004.         log_info('キャンセル通知メール送信処理開始', ['id' => $Order->getId()]);
  1005.         // キャンセル通知用のメールテンプレートを取得
  1006.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_cancel_customer_mail_template_id']);
  1007.         // メール本文の生成
  1008.         $body $this->twig->render($MailTemplate->getFileName(), [
  1009.             'BaseInfo' => $this->BaseInfo,
  1010.             'Order' => $Order
  1011.         ]);
  1012.         $message = (new Email())
  1013.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1014.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1015.             ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  1016.             // ->bcc($this->BaseInfo->getEmail04())
  1017.             ->replyTo($this->BaseInfo->getEmail03())
  1018.             ->returnPath($this->BaseInfo->getEmail04())
  1019.             ->text($body);
  1020.         
  1021.         // 代理運用フラグが立っている場合はメールを送信しない
  1022.         $Customer $Order->getCustomer();
  1023.         if ($Customer->getAgentOperationFlag()) {
  1024.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  1025.             return;
  1026.         }
  1027.         try {
  1028.             $this->mailer->send($message);
  1029.         } catch (TransportExceptionInterface $e) {
  1030.             log_critical($e->getMessage());
  1031.         }
  1032.         $MailHistory = new MailHistory();
  1033.         $MailHistory->setMailSubject($message->getSubject())
  1034.             ->setMailBody($message->getTextBody())
  1035.             ->setOrder($Order)
  1036.             ->setSendDate(new \DateTime());
  1037.         $this->mailHistoryRepository->save($MailHistory);
  1038.         log_info('キャンセル通知メール送信処理完了', ['id' => $Order->getId()]);
  1039.     }
  1040.     /**
  1041.      * キャンセル通知メールを管理者向けに送信する.
  1042.      *
  1043.      * @param Order $Order
  1044.      *
  1045.      * @throws \Twig_Error
  1046.      */
  1047.     public function sendCancelNotifyMailToAdmin(Order $Order)
  1048.     {
  1049.         log_info('管理者向けキャンセル通知メール送信処理開始', ['id' => $Order->getId()]);
  1050.         // 管理者向けキャンセル通知用のメールテンプレートを取得
  1051.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_cancel_admin_mail_template_id']);
  1052.         // メール本文の生成
  1053.         $body $this->twig->render($MailTemplate->getFileName(), [
  1054.             'BaseInfo' => $this->BaseInfo,
  1055.             'Order' => $Order
  1056.         ]);
  1057.         // 複数アドレスの設定
  1058.         $addresses = [
  1059.             $this->BaseInfo->getEmail04(),
  1060.             // 他のアドレスも追加可能
  1061.         ];
  1062.         $message = (new Email())
  1063.              ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1064.              ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()));
  1065.         foreach ($addresses as $address) {
  1066.             // 各アドレスをメールの送信先として追加する
  1067.             $message->addTo($address);
  1068.         }
  1069.         $message
  1070.             ->replyTo($this->BaseInfo->getEmail03())
  1071.             ->returnPath($this->BaseInfo->getEmail04())
  1072.             ->text($body);
  1073.         // $message = (new Email())
  1074.         //     ->subject('[' . $this->BaseInfo->getShopName() . '] ' . $MailTemplate->getMailSubject())
  1075.         //     ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1076.         //     ->to($this->BaseInfo->getEmail01())
  1077.         //     ->bcc($this->BaseInfo->getEmail01())
  1078.         //     ->replyTo($this->BaseInfo->getEmail03())
  1079.         //     ->returnPath($this->BaseInfo->getEmail04())
  1080.         //     ->text($body);
  1081.         try {
  1082.             $this->mailer->send($message);
  1083.         } catch (TransportExceptionInterface $e) {
  1084.             log_critical($e->getMessage());
  1085.         }
  1086.         log_info('管理者向けキャンセル通知メール送信処理完了', ['id' => $Order->getId()]);
  1087.     }
  1088.     /**
  1089.      * 通常購入決済エラー時のキャンセルメール
  1090.      *
  1091.      * @param Order $Order
  1092.      *
  1093.      * @throws \Twig_Error
  1094.      */
  1095.     public function sendCancelCreditErrorMail(Order $Order)
  1096.     {
  1097.         log_info('通常購入決済エラーキャンセル通知メール送信処理開始', ['id' => $Order->getId()]);
  1098.         // キャンセル通知用のメールテンプレートを取得
  1099.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_cancel_credit_error_mail_template_id']);
  1100.         // メール本文の生成
  1101.         $body $this->twig->render($MailTemplate->getFileName(), [
  1102.             'BaseInfo' => $this->BaseInfo,
  1103.             'Order' => $Order
  1104.         ]);
  1105.          // 複数アドレスの設定
  1106.          $addresses = [
  1107.             $this->convertRFCViolatingEmail($Order->getEmail()),
  1108.             $this->BaseInfo->getEmail04(),
  1109.             // 他のアドレスも追加可能
  1110.         ];
  1111.         $message = (new Email())
  1112.              ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1113.              ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()));
  1114.         foreach ($addresses as $address) {
  1115.             // 各アドレスをメールの送信先として追加する
  1116.             $message->addTo($address);
  1117.         }
  1118.         $message
  1119.             ->bcc($this->BaseInfo->getEmail04())
  1120.             ->replyTo($this->BaseInfo->getEmail03())
  1121.             ->returnPath($this->BaseInfo->getEmail04())
  1122.             ->text($body);
  1123.         // $message = (new Email())
  1124.         //     ->subject('[' . $this->BaseInfo->getShopName() . '] ' . $MailTemplate->getMailSubject())
  1125.         //     ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1126.         //     ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  1127.         //     ->bcc($this->BaseInfo->getEmail01())
  1128.         //     ->replyTo($this->BaseInfo->getEmail03())
  1129.         //     ->returnPath($this->BaseInfo->getEmail04())
  1130.         //     ->text($body);
  1131.         // 代理運用フラグが立っている場合はメールを送信しない
  1132.         $Customer $Order->getCustomer();
  1133.         if ($Customer->getAgentOperationFlag()) {
  1134.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  1135.             return;
  1136.         }
  1137.         try {
  1138.             $this->mailer->send($message);
  1139.         } catch (TransportExceptionInterface $e) {
  1140.             log_critical($e->getMessage());
  1141.         }
  1142.         $MailHistory = new MailHistory();
  1143.         $MailHistory->setMailSubject($message->getSubject())
  1144.             ->setMailBody($message->getTextBody())
  1145.             ->setOrder($Order)
  1146.             ->setSendDate(new \DateTime());
  1147.         $this->mailHistoryRepository->save($MailHistory);
  1148.         log_info('通常購入決済エラー通知メール送信処理完了', ['id' => $Order->getId()]);
  1149.     }
  1150.     /**
  1151.      * 超過取消時のキャンセルメール
  1152.      *
  1153.      * @param Order $Order
  1154.      *
  1155.      * @throws \Twig_Error
  1156.      */
  1157.     public function sendCancelExcessMail(Order $Order)
  1158.     {
  1159.         log_info('超過取消キャンセル通知メール送信処理開始', ['id' => $Order->getId()]);
  1160.         // キャンセル通知用のメールテンプレートを取得
  1161.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_cancel_excess_mail_template_id']);
  1162.         // メール本文の生成
  1163.         $body $this->twig->render($MailTemplate->getFileName(), [
  1164.             'BaseInfo' => $this->BaseInfo,
  1165.             'Order' => $Order
  1166.         ]);
  1167.         // 複数アドレスの設定
  1168.         $addresses = [
  1169.             $this->convertRFCViolatingEmail($Order->getEmail()),
  1170.             // $this->BaseInfo->getEmail04(),
  1171.             // 他のアドレスも追加可能
  1172.         ];
  1173.         $message = (new Email())
  1174.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1175.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()));
  1176.         foreach ($addresses as $address) {
  1177.             // 各アドレスをメールの送信先として追加する
  1178.             $message->addTo($address);
  1179.         }
  1180.         $message
  1181.             // ->bcc($this->BaseInfo->getEmail04())
  1182.             ->replyTo($this->BaseInfo->getEmail03())
  1183.             ->returnPath($this->BaseInfo->getEmail04())
  1184.             ->text($body);
  1185.         // $message = (new Email())
  1186.         //     ->subject('[' . $this->BaseInfo->getShopName() . '] ' . $MailTemplate->getMailSubject())
  1187.         //     ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1188.         //     ->to($this->convertRFCViolatingEmail($Order->getEmail()))
  1189.         //     ->bcc($this->BaseInfo->getEmail01())
  1190.         //     ->replyTo($this->BaseInfo->getEmail03())
  1191.         //     ->returnPath($this->BaseInfo->getEmail04())
  1192.         //     ->text($body);
  1193.         // 代理運用フラグが立っている場合はメールを送信しない
  1194.         $Customer $Order->getCustomer();
  1195.         if ($Customer->getAgentOperationFlag()) {
  1196.             log_info('代理運用フラグがONのため、仮会員登録メールを送信しません。');
  1197.             return;
  1198.         }
  1199.         try {
  1200.             $this->mailer->send($message);
  1201.         } catch (TransportExceptionInterface $e) {
  1202.             log_critical($e->getMessage());
  1203.         }
  1204.         $MailHistory = new MailHistory();
  1205.         $MailHistory->setMailSubject($message->getSubject())
  1206.             ->setMailBody($message->getTextBody())
  1207.             ->setOrder($Order)
  1208.             ->setSendDate(new \DateTime());
  1209.         $this->mailHistoryRepository->save($MailHistory);
  1210.         log_info('通常購入決済エラー通知メール送信処理完了', ['id' => $Order->getId()]);
  1211.     }
  1212.     /**
  1213.      * 発送確認通知メールを管理者向けに送信する.
  1214.      *
  1215.      * @param Order $Order
  1216.      *
  1217.      * @throws \Twig_Error
  1218.      */
  1219.     public function sendUnDeliveredNotifyMailToAdmin($Orders)
  1220.     {
  1221.         log_info('管理者向け発送確認通知メール送信処理開始');
  1222.         // 管理者向け発送確認通知用のメールテンプレートを取得
  1223.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_un_deliver_mail_template_id']);
  1224.         // メール本文の生成
  1225.         $body $this->twig->render($MailTemplate->getFileName(), [
  1226.             'BaseInfo' => $this->BaseInfo,
  1227.             'Orders' => $Orders
  1228.         ]);
  1229.         $message = (new Email())
  1230.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1231.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1232.             ->to($this->BaseInfo->getEmail04())
  1233.             ->bcc($this->BaseInfo->getEmail04())
  1234.             ->replyTo($this->BaseInfo->getEmail03())
  1235.             ->returnPath($this->BaseInfo->getEmail04())
  1236.             ->text($body);
  1237.         try {
  1238.             $this->mailer->send($message);
  1239.         } catch (TransportExceptionInterface $e) {
  1240.             log_critical($e->getMessage());
  1241.         }
  1242.         log_info('管理者向け発送確認通知メール送信処理完了');
  1243.     }
  1244.     /**
  1245.      * 定期受注の次回配送予定商品の通知メールを工場向けに送信する.
  1246.      *
  1247.      * 
  1248.      *
  1249.      * 
  1250.      */
  1251.     public function sendNextRegularOrderToFactory($regularOrders$regularOrdersOneAfterAnother$nextDeliveryDate$OneAfterAnotherDeliveryDate)
  1252.     {
  1253.         log_info('定期受注の次回配送予定商品の通知メール工場向けに送信処理開始');
  1254.         // 定期受注の次回配送予定商品の通知メールテンプレートを取得
  1255.         $MailTemplate $this->mailTemplateRepository->find($this->eccubeConfig['eccube_next_regular_order_to_factory_mail_template_id']);
  1256.         // メール本文の生成
  1257.         $body $this->twig->render($MailTemplate->getFileName(), [
  1258.             'BaseInfo' => $this->BaseInfo,
  1259.             'regularOrders' => $regularOrders,
  1260.             'regularOrdersOneAfterAnother' => $regularOrdersOneAfterAnother,
  1261.             'nextDeliveryDate' => $nextDeliveryDate,
  1262.             'OneAfterAnotherDeliveryDate' => $OneAfterAnotherDeliveryDate,
  1263.         ]);
  1264.         $message = (new Email())
  1265.             ->subject('[' $this->BaseInfo->getShopName() . '] ' $MailTemplate->getMailSubject())
  1266.             ->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
  1267.             ->to($this->BaseInfo->getEmail06())
  1268.             ->bcc($this->BaseInfo->getEmail06())
  1269.             ->returnPath($this->BaseInfo->getEmail04())
  1270.             ->text($body);
  1271.         try {
  1272.             $this->mailer->send($message);
  1273.         } catch (TransportExceptionInterface $e) {
  1274.             log_critical($e->getMessage());
  1275.         }
  1276.         log_info('定期受注の次回配送予定商品の通知メール工場向けに送信処理開始完了');
  1277.     }
  1278. }