Php 如何在Shopware 6控制器中发送电子邮件?

Php 如何在Shopware 6控制器中发送电子邮件?,php,symfony,email,e-commerce,shopware,Php,Symfony,Email,E Commerce,Shopware,在Shopware 5中有一个mail->send()函数,用于发送包含所需模板和内容的电子邮件。 Shopware 6中的函数名是什么 另外,我看到一些文件,我认为是需要的,一些邮件发送的例子将受到欢迎 Shopware\Core\Content\MailTemplate\Service\MessageFactory.php Shopware\Core\Content\MailTemplate\Service\MailSender.php 在Shopware 6中,您还可以使用邮件服务,为您

在Shopware 5中有一个
mail->send()
函数,用于发送包含所需模板和内容的电子邮件。 Shopware 6中的函数名是什么

另外,我看到一些文件,我认为是需要的,一些邮件发送的例子将受到欢迎

Shopware\Core\Content\MailTemplate\Service\MessageFactory.php
Shopware\Core\Content\MailTemplate\Service\MailSender.php

在Shopware 6中,您还可以使用邮件服务,为您提供

因此,基本上,使用该服务的一个非常简单的示例是:

public function __construct(
    MailServiceInterface $mailService,
) {
    $this->mailService = $mailService;
}

private function sendMyMail(SalesChannelContext $salesChannelContext): void
{
    $data = new ParameterBag();
    $data->set(
        'recipients',
        [
            'foo@bar.com' => 'John Doe'
        ]
    );

    $data->set('senderName', 'I am the Sender');

    $data->set('contentHtml', 'Foo bar');
    $data->set('contentPlain', 'Foo bar');
    $data->set('subject', 'The subject');
    $data->set('salesChannelId', $salesChannelContext->getSalesChannel()->getId());

    $this->mailService->send(
        $data->all(),
        $salesChannelContext->getContext(),
    );
}
还要确保在
services.xml
中标记服务

<service id="Your\Namespace\Services\YourSendService">
  <argument id="Shopware\Core\Content\MailTemplate\Service\MailService" type="service"/>
</service>
您可以稍后设置来自您的电子邮件模板(也可在管理中使用)的电子邮件值,而不是在发送方法中对其进行硬编码

$data->set('contentHtml', $mailTemplate->getContentHtml());
$data->set('contentPlain', $mailTemplate->getContentPlain());
$data->set('subject', $mailTemplate->getSubject());

我和你做的完全一样,但什么也没发生!探查器说,我有一条消息在spool中。如果我使用控制台命令swiftmailer:email:send测试我的连接,则发送在按下enter键的同时收到的邮件。当我注册到商店时,邮件立即出现。当我尝试使用swiftmailer:spool:send提交假脱机时,它会显示:已发送0封电子邮件。我错在哪里?为什么没有使用池的文档?有人能帮我吗?这里的代码是正确的,@ThomasDeutschländer这可能是因为错误的电子邮件配置。您也可以查看此链接:
$data->set('contentHtml', $mailTemplate->getContentHtml());
$data->set('contentPlain', $mailTemplate->getContentPlain());
$data->set('subject', $mailTemplate->getSubject());