<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Service;
use Doctrine\ORM\NonUniqueResultException;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\MailHistory;
use Eccube\Entity\MailTemplate;
use Eccube\Entity\Order;
use Eccube\Entity\OrderItem;
use Eccube\Entity\Shipping;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\MailHistoryRepository;
use Eccube\Repository\MailTemplateRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class MailService
{
/**
* @var MailerInterface
*/
protected $mailer;
/**
* @var MailTemplateRepository
*/
protected $mailTemplateRepository;
/**
* @var MailHistoryRepository
*/
protected $mailHistoryRepository;
/**
* @var EventDispatcher
*/
protected $eventDispatcher;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* @var \Twig\Environment
*/
protected $twig;
/** @var ContainerInterface */
protected $container;
/**
* MailService constructor.
*
* @param MailerInterface $mailer
* @param MailTemplateRepository $mailTemplateRepository
* @param MailHistoryRepository $mailHistoryRepository
* @param BaseInfoRepository $baseInfoRepository
* @param EventDispatcherInterface $eventDispatcher
* @param \Twig\Environment $twig
* @param EccubeConfig $eccubeConfig
* @param ContainerInterface $container
*/
public function __construct(
MailerInterface $mailer,
MailTemplateRepository $mailTemplateRepository,
MailHistoryRepository $mailHistoryRepository,
BaseInfoRepository $baseInfoRepository,
EventDispatcherInterface $eventDispatcher,
\Twig\Environment $twig,
EccubeConfig $eccubeConfig,
ContainerInterface $container
) {
$this->mailer = $mailer;
$this->mailTemplateRepository = $mailTemplateRepository;
$this->mailHistoryRepository = $mailHistoryRepository;
$this->BaseInfo = $baseInfoRepository->get();
$this->eventDispatcher = $eventDispatcher;
$this->eccubeConfig = $eccubeConfig;
$this->twig = $twig;
$this->container = $container;
}
/**
* Send customer confirm mail.
*
* @param $Customer 会員情報
* @param string $activateUrl アクティベート用url
*/
public function sendCustomerConfirmMail(Customer $Customer, $activateUrl)
{
log_info('仮会員登録メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_CONFIRM);
try {
$this->mailer->send($message);
log_info('仮会員登録メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send customer complete mail.
*
* @param $Customer 会員情報
*/
public function sendCustomerCompleteMail(Customer $Customer)
{
log_info('会員登録完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_complete_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_COMPLETE);
try {
$this->mailer->send($message);
log_info('会員登録完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send withdraw mail.
*
* @param $Customer Customer
* @param $email string
*/
public function sendCustomerWithdrawMail(Customer $Customer, string $email)
{
log_info('退会手続き完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_customer_withdraw_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($email))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'email' => $email,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CUSTOMER_WITHDRAW);
try {
$this->mailer->send($message);
log_info('退会手続き完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send contact mail.
*
* @param $formData お問い合わせ内容
*/
public function sendContactMail($formData)
{
log_info('お問い合わせ受付メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_contact_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'data' => $formData,
'BaseInfo' => $this->BaseInfo,
]);
// 問い合わせ者にメール送信
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail02(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($formData['email']))
->bcc($this->BaseInfo->getEmail02())
->replyTo($this->BaseInfo->getEmail02())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'data' => $formData,
'BaseInfo' => $this->BaseInfo,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'formData' => $formData,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_CONTACT);
try {
$this->mailer->send($message);
log_info('お問い合わせ受付メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send order mail.
*
* @param \Eccube\Entity\Order $Order 受注情報
*
* @return Email
*/
public function sendOrderMail(Order $Order)
{
log_info('受注メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_order_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'Order' => $Order,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'Order' => $Order,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Order' => $Order,
'MailTemplate' => $MailTemplate,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ORDER);
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
$MailHistory = new MailHistory();
$MailHistory->setMailSubject($message->getSubject())
->setMailBody($message->getTextBody())
->setOrder($Order)
->setSendDate(new \DateTime());
// HTML用メールの設定
$htmlBody = $message->getHtmlBody();
if (!empty($htmlBody)) {
$MailHistory->setMailHtmlBody($htmlBody);
}
$this->mailHistoryRepository->save($MailHistory);
log_info('受注メール送信完了');
return $message;
}
/**
* Send admin customer confirm mail.
*
* @param $Customer 会員情報
* @param string $activateUrl アクティベート用url
*/
public function sendAdminCustomerConfirmMail(Customer $Customer, $activateUrl)
{
log_info('仮会員登録再送メール送信開始');
/* @var $MailTemplate \Eccube\Entity\MailTemplate */
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_entry_confirm_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'activateUrl' => $activateUrl,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'activateUrl' => $activateUrl,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'activateUrl' => $activateUrl,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM);
try {
$this->mailer->send($message);
log_info('仮会員登録再送メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send admin order mail.
*
* @param Order $Order 受注情報
* @param $formData 入力内容
*
* @return Email
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function sendAdminOrderMail(Order $Order, $formData)
{
log_info('受注管理通知メール送信開始');
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$formData['mail_subject'])
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04())
->text($formData['tpl_data']);
$event = new EventArgs(
[
'message' => $message,
'Order' => $Order,
'formData' => $formData,
'BaseInfo' => $this->BaseInfo,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_ADMIN_ORDER);
try {
$this->mailer->send($message);
log_info('受注管理通知メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
return $message;
}
/**
* Send password reset notification mail.
*
* @param $Customer 会員情報
* @param string $reset_url
*/
public function sendPasswordResetNotificationMail(Customer $Customer, $reset_url)
{
log_info('パスワード再発行メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_forgot_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
'reset_url' => $reset_url,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'expire' => $this->eccubeConfig['eccube_customer_reset_expire'],
'reset_url' => $reset_url,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'resetUrl' => $reset_url,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_PASSWORD_RESET);
try {
$this->mailer->send($message);
log_info('パスワード再発行メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* Send password reset notification mail.
*
* @param $Customer 会員情報
* @param string $password
*/
public function sendPasswordResetCompleteMail(Customer $Customer, $password)
{
log_info('パスワード変更完了メール送信開始');
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_reset_complete_mail_template_id']);
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'password' => $password,
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'password' => $password,
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
$event = new EventArgs(
[
'message' => $message,
'Customer' => $Customer,
'BaseInfo' => $this->BaseInfo,
'password' => $password,
],
null
);
$this->eventDispatcher->dispatch($event, EccubeEvents::MAIL_PASSWORD_RESET_COMPLETE);
try {
$this->mailer->send($message);
log_info('パスワード変更完了メール送信完了');
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
/**
* 発送通知メールを送信する.
* 発送通知メールは受注ごとに送られる
*
* @param Shipping $Shipping
*
* @throws \Twig_Error
*/
public function sendShippingNotifyMail(Shipping $Shipping)
{
log_info('出荷通知メール送信処理開始', ['id' => $Shipping->getId()]);
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
/** @var Order $Order */
$Order = $Shipping->getOrder();
$body = $this->getShippingNotifyMailBody($Shipping, $Order, $MailTemplate->getFileName());
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Order->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->getShippingNotifyMailBody($Shipping, $Order, $htmlFileName, true);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
$MailHistory = new MailHistory();
$MailHistory->setMailSubject($message->getSubject())
->setMailBody($message->getTextBody())
->setOrder($Order)
->setSendDate(new \DateTime());
// HTML用メールの設定
$htmlBody = $message->getHtmlBody();
if (!empty($htmlBody)) {
$MailHistory->setMailHtmlBody($htmlBody);
}
$this->mailHistoryRepository->save($MailHistory);
log_info('出荷通知メール送信処理完了', ['id' => $Shipping->getId()]);
}
/**
* @param Shipping $Shipping
* @param Order $Order
* @param string|null $templateName
* @param boolean $is_html
*
* @return string
*
* @throws \Twig_Error
*/
public function getShippingNotifyMailBody(Shipping $Shipping, Order $Order, $templateName = null, $is_html = false)
{
$ShippingItems = array_filter($Shipping->getOrderItems()->toArray(), function (OrderItem $OrderItem) use ($Order) {
return $OrderItem->getOrderId() === $Order->getId();
});
if (is_null($templateName)) {
/** @var MailTemplate $MailTemplate */
$MailTemplate = $this->mailTemplateRepository->find($this->eccubeConfig['eccube_shipping_notify_mail_template_id']);
$fileName = $MailTemplate->getFileName();
} else {
$fileName = $templateName;
}
if ($is_html) {
$htmlFileName = $this->getHtmlTemplate($fileName);
$fileName = !is_null($htmlFileName) ? $htmlFileName : $fileName;
}
return $this->twig->render($fileName, [
'Shipping' => $Shipping,
'ShippingItems' => $ShippingItems,
'Order' => $Order,
]);
}
/**
* 会員情報変更時にメール通知
*
* @param Customer $Customer
* @param array $userData
* - userAgent
* - ipAddress
* - preEmail
* @param string $eventName
*
* @return void
*
* @throws LoaderError
* @throws NonUniqueResultException
* @throws RuntimeError
* @throws SyntaxError
*/
public function sendCustomerChangeNotifyMail(Customer $Customer, array $userData, string $eventName)
{
log_info('会員情報変更通知メール送信処理開始');
log_info($eventName);
// メールテンプレートの取得 IDでの取得は現行環境での差異があるため
$tpl_name = 'Mail/customer_change_notify.twig';
$MailTemplate = $this->mailTemplateRepository->createQueryBuilder('mt')
->where('mt.file_name = :file_name')
->setParameter('file_name', $tpl_name)
->getQuery()
->getOneOrNullResult();
$body = $this->twig->render($MailTemplate->getFileName(), [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'userAgent' => $userData['userAgent'],
'eventName' => $eventName,
'ipAddress' => $userData['ipAddress'],
]);
$message = (new Email())
->subject('['.$this->BaseInfo->getShopName().'] '.$MailTemplate->getMailSubject())
->from(new Address($this->BaseInfo->getEmail01(), $this->BaseInfo->getShopName()))
->to($this->convertRFCViolatingEmail($Customer->getEmail()))
->bcc($this->BaseInfo->getEmail01())
->replyTo($this->BaseInfo->getEmail03())
->returnPath($this->BaseInfo->getEmail04());
// HTMLテンプレートが存在する場合
$htmlFileName = $this->getHtmlTemplate($MailTemplate->getFileName());
if (!is_null($htmlFileName)) {
$htmlBody = $this->twig->render($htmlFileName, [
'BaseInfo' => $this->BaseInfo,
'Customer' => $Customer,
'userAgent' => $userData['userAgent'],
'eventName' => $eventName,
'ipAddress' => $userData['ipAddress'],
]);
$message
->text($body)
->html($htmlBody);
} else {
$message->text($body);
}
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
// メールアドレスの変更があった場合、変更前のメールアドレスにも送信
if (isset($userData['preEmail']) && $Customer->getEmail() != $userData['preEmail']) {
$message->to($this->convertRFCViolatingEmail($userData['preEmail']));
// メール送信
try {
$this->mailer->send($message);
} catch (TransportExceptionInterface $e) {
log_critical($e->getMessage());
}
}
log_info('会員情報変更通知メール送信処理完了');
}
/**
* [getHtmlTemplate description]
*
* @param string $templateName プレーンテキストメールのファイル名
*
* @return string|null 存在する場合はファイル名を返す
*/
public function getHtmlTemplate($templateName)
{
// メールテンプレート名からHTMLメール用テンプレート名を生成
$fileName = explode('.', $templateName);
$suffix = '.html';
$htmlFileName = $fileName[0].$suffix.'.'.$fileName[1];
// HTMLメール用テンプレートの存在チェック
if ($this->twig->getLoader()->exists($htmlFileName)) {
return $htmlFileName;
} else {
return null;
}
}
/**
* RFC違反のメールの local part を "" で囲む.
*
* パラメータ eccube_rfc_email_check == true の場合は変換しない
*
* @param string $email
*
* @return Address
*/
public function convertRFCViolatingEmail(string $email): Address
{
if ($this->container->getParameter('eccube_rfc_email_check')) {
return new Address($email);
}
// see https://blog.everqueue.com/chiba/2009/03/22/163/
$wsp = '[\x20\x09]';
$vchar = '[\x21-\x7e]';
$quoted_pair = "\\\\(?:$vchar|$wsp)";
$qtext = '[\x21\x23-\x5b\x5d-\x7e]';
$qcontent = "(?:$qtext|$quoted_pair)";
$quoted_string = "\"$qcontent*\"";
$atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]';
$dot_atom = "$atext+(?:[.]$atext+)*";
$local_part = "(?:$dot_atom|$quoted_string)";
$domain = $dot_atom;
$addr_spec = "{$local_part}[@]$domain";
$dot_atom_loose = "$atext+(?:[.]|$atext)*";
$local_part_loose = "(?:$dot_atom_loose|$quoted_string)";
$addr_spec_loose = "{$local_part_loose}[@]$domain";
$regexp = "/\A{$addr_spec}\z/";
if (!preg_match($regexp, $email)) {
$email = preg_replace('/^(.*)@(.*)$/', '"$1"@$2', $email);
}
return new Address($email);
}
}