试图调用名为“newInstance"的未定义方法;类“Swift_Message" [英] Attempted to call an undefined method named "newInstance" of class "Swift_Message"

查看:15
本文介绍了试图调用名为“newInstance"的未定义方法;类“Swift_Message"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天以来,我无法再使用 Symfony 和 Swiftmailer 发送电子邮件,尽管我使用的是文档中的代码

Since a few days I can't send email anymore using Symfony and Swiftmailer, though I'm using the code from the documentation

private function _sendResetPasswordEmail(UserInterface $user)
{   
    $subject = $this->get('translator')->trans('email-title-reset-password');
    $message = \Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom('contact@example.com')
        ->setTo($user->getEmail())
        ->setBody(
            $this->renderView(
                'reset-password-email.html.twig',
                ['user' => $user]
            ),
            'text/html'
        )
    ;
    $this->get('mailer')->send($message);
}   

它曾经有效

现在我可以在日志中看到

and now I can see in the logs

"Attempted to call an undefined method named "newInstance" of class "Swift_Message"

什么可以改变?

推荐答案

实际上在发布问题并链接到文档时,我很惊讶地看到它已更新

Actually while posting the question and linking to the documentation, I was surprised to see it was updated

现在是

 $message = (new \Swift_Message('Hello Email'))

代替

 $message = \Swift_Message::newInstance()
       ->setSubject('Hello Email')

自 swiftmailer6 发布以来,根据变更日志

since the release of swiftmailer6 according to the changelog

https://github.com/swiftmailer/swiftmailer/blob/master/变化#L24

很遗憾没有弃用"期.

这篇关于试图调用名为“newInstance"的未定义方法;类“Swift_Message"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆