【发布时间】:2019-07-21 06:42:02
【问题描述】:
我尝试通过 symfony 命令发送邮件(swiftmail)。 这是我的代码:
class CommandMail extends Command
{
protected static $defaultName = 'app:send-daily-mail';
protected function configure() {
$this
->setDescription('Send automatic reminders mail everyday.')
->setHelp('This command allows you to send automatic reminder mail to Rhys, everyday...');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$message = (new \Swift_Message('test auto mail cron 12 24 TEST'))
->setFrom('xxxxxx.xxxxxxx@gmail.com')
->setTo('wwwww.wwwwwww@gmail.com')
->setBody('test body');
$this->get('mailer')->send($message);
}
}
我有以下错误:
在 CommandMail.php 第 54 行: 试图调用类的名为“get”的未定义方法 “AppBundle\Command\CommandMail”。
你的意思是打电话给例如“getAliases”、“getApplication”、 “getDefaultName”、“getDefinition”、“getDescription”、“getHelp”、 “getHelper”、“getHelperSet”、“getName”、“getNativeDefin ition”、 “getProcessedHelp”、“getSynopsis”还是“getUsages”?
我尝试了很多东西(getContainer() ie 和许多其他方法),但没有任何效果。
感谢您的帮助!
(Symfony 3,SMTP gmail)
【问题讨论】:
-
我尝试编辑我的消息“嗨!!”不工作!理解我是新人:)
-
你使用的是哪个版本的 Symfony?
-
Symfony 3.4 正常(symfony 3 肯定)
-
我使用 swiftmailer 和 gmail smtp
标签: symfony email cron command