【发布时间】:2019-05-01 07:15:12
【问题描述】:
我使用的是 lumen 框架,它是 laravel 的微框架 我必须为发送的电子邮件创建 cron, 我已将文件放在 app/console/commands 中
在 kernel.php 文件中注册我的命令
一切正常,我已经检查过了
现在在文件中调用了下面的模型代码来发送电子邮件,
$sent = Mail::send(['html' => 'email_render'], ['html' => $data["body"]], function ($msg) use ($data) {
$msg->from($data["from_address"])
->to($data["to_address"])->subject($data["subject"]);//->setBody($data["body"]);
if (isset($data["cc_address"]) && $data["cc_address"]) {
$msg->cc($data["cc_address"]);
}
if (isset($data["bcc_address"]) && $data["bcc_address"]) {
$msg->bcc($data["bcc_address"]);
}
if (isset($data["attachment"]) && $data["attachment"]) {
foreach ($data["attachment"] as $attachment) {
$msg->attach($attachment['file'], $attachment['options']);
}
}
if (isset($data["message_id"]) && $data["message_id"] && $data["type"] != "compose") {
$msg->getSwiftMessage()->getHeaders()->addTextHeader("In-Reply-To", "<".$data["message_id"].">");
$msg->getSwiftMessage()->getHeaders()->addTextHeader("References", self::getReferances($data));
}
});
它给了我如下错误,
[RuntimeException] ←[39;49m
←[37;41m No supported encrypter found. The cipher and / or key length are invalid.
如果我从控制器调用相同的模型函数然后它正在工作但从命令调用它然后它给我错误,
有什么理由吗?
我找到了解决方案,
在流明框架中,我无法使用命令生成密钥
artisan key:generate
解决方案
我已经使用下面的 url 生成它,
Lumen Micro Framework => php artisan key:generate
然后运行我的命令它正在发送电子邮件,
但是不知道为什么它之前使用控制器而不使用命令。
【问题讨论】:
标签: php laravel lumen swiftmailer