SwiftMailer无法发送TemplatedEmail,symfony 4

问题描述 投票:-1回答:1

这是swiftmailer所说的,尽管sym​​fony 4文档说我们非常喜欢发送这样的TemplatedEmail对象,但这是不可能的:

传递给Swift_Mailer :: send()的参数1必须是Swift_Mime_SimpleMessage,实例给定的Symfony \ Bridge \ Twig \ Mime \ TemplatedEmail,称为/home/tk/html/src/Service/MailService.php,第103行

在我的MailService中发送我的html邮件的代码:

// ...
use Swift_Mailer;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;

class MailService {

// ...

public function sendOwnerPollsAction( Owner $foundOwner ) {

        // anti spam , limit to every minute TODO
//      $lastSend = $admin_user->getRequestedPollsDate();
//      $now      = new \DateTime();

//      if ( date_diff( $lastSend, $now ) < 60 ) {
//          // too soon!
//          die( 'too soon!' );
//      }
//      $admin_user->setRequestedPollsDate( $now );
//      $em->persist( $admin_user );
//      $em->flush();
        $titleEmail = 'Framadate | Mes sondages';

        $templateVars = [
            'owner'          => $foundOwner,
            'title'          => $titleEmail,
            'email_template' => 'emails/owner-list.html.twig',
        ];

        $email = ( new TemplatedEmail() )
            ->from( '[email protected]' )
            ->to( new Address( $foundOwner->getEmail() ) )
            ->subject( $titleEmail )
            ->htmlTemplate( $templateVars[ 'email_template' ] )
            ->context( $templateVars );

        // send email
        return $this->mailer->send( $email );
    }

symfony 4的swiftmailer文档说我们可以发送这样的邮件,并且templatedemail扩展了Email。https://symfony.com/doc/4.3/mailer.html#creating-sending-messages所以我不知道如何发送模板化的html电子邮件。

包装:

"symfony/framework-bundle": "4.3.*",
"symfony/swiftmailer-bundle": "^3.4",
"php": "^7.1.3",
php symfony email swiftmailer
1个回答
0
投票

您正在将Symfony Mailer与Swift Mailer混合。

© www.soinside.com 2019 - 2024. All rights reserved.