Php 在symfony(Swiftmailer)中扩展现有电子邮件的最佳方法?
我有一份登记表,在提交时会发送一封电子邮件。现在我的目标是在电子邮件到达用户之前获取它并扩展它。我正在使用基于Symfony的Showpare6 我已经拥有的: 订户:Php 在symfony(Swiftmailer)中扩展现有电子邮件的最佳方法?,php,symfony,Php,Symfony,我有一份登记表,在提交时会发送一封电子邮件。现在我的目标是在电子邮件到达用户之前获取它并扩展它。我正在使用基于Symfony的Showpare6 我已经拥有的: 订户: <?php namespace RegistrationExtension\Subscriber; use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent; use Symfony\Component\EventDispatcher
<?php
namespace RegistrationExtension\Subscriber;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Checkout\Customer\CustomerEntity;
class RegisterExtensionSubscriber implements EventSubscriberInterface{
public static function getSubscribedEvents(): array
{
return [
CustomerEvents::CUSTOMER_REGISTER_EVENT => 'onCustomRegister'
];
}
public function onCustomRegister(EntityLoadedEvent $event){
/** @var CustomerEntity $customerRegisEvent */
foreach ($event->getEntities() as $customerRegisEvent) {
$customerRegisEvent->addExtension('custom_struct', new RegisterStruct());
}
}
}
我的确切目标是上传一张图片,并将链接作为下载链接放在邮件中
<?php declare(strict_types=1);
namespace RegistrationExtension\Storefront\Controller;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
/**
* @RouteScope(scopes={"storefront"})
*/
class RegistrationExtensionController extends StorefrontController{
/**
* @Route("/extension", name="registration.extension", defaults={"XmlHttpRequest"=true})
*/
public function extendRegisterStorefront(SalesChannelContext $context){
/**
* @var EntityRepositoryInterface $mailTypeRepository
* @var EntityRepositoryInterface $mailRepository
*/
$mailTypeRepository = $this->container->get('mail_template_type.repository');
$mailRepository = $this->container->get('mail_template.repository');
$mailEntity = $mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$context->getContext()
);
$mailTypeId = $mailEntity->getEntities()->first()->getId();
$mailEntity = $mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailTypeId)),
$context->getContext()
);
//$mailEntity->getEntities()->setContentHtml("test");
$mail = $mailEntity->getEntities();
return $this->renderStorefront(
'@RegistrationExtension/storefront/custom.html.twig',
[
'page' => $context,
'mailEntity' => $mail
]
);
}
}
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="RegistrationExtension\Storefront\Controller\RegistrationExtensionController" public="true"> </service>
<service id="RegistrationExtension\Subscriber\RegisterExtensionSubscriber">
<tag name="kernel.event_subscriber"/>
</service>
</services>
</container>