OctoberCMS - Mail::send(),未定义的变量 - Laravel
OctoberCMS - Mail::send(), Undefined variables - Laravel
我正在尝试将 SAME 电子邮件发送到数组中给出的 多个 地址$emails
.
我创建了一个名为 SendMail
的 class,里面是一个接受 2 个参数的 sendPost()
方法:
($post, $emails)
这是我的代码:
class SendMail {
public static function sendPost($post, $emails)
{
Mail::send('acme.blog::mail.message', $post, function($message) {
$message->to($emails);
$message->from('mail@compuflexcorp.com', 'Compuflex Mail');
$message->subject($post['subject']);
$message->replyTo($post['email']);
});
}
}
问题是,我一直收到错误消息:
"Undefined variable $emails" on Line 14 of C:\...\SendMail.php
第 14 行:$message->to($emails);
我尝试过的:
我查看是否可以访问 sendPost()
的 $post
和 $emails
变量 inside,但是Mail::send()
之外。答案是 YES,我可以访问 $post
和 $emails
里面的信息 sendPost()
],所以变量实际上被传递给了 sendPost()
方法。
一开始,我认为这与 $emails
不是 Mail::send()
的参数之一有关,所以我把 $post
和 $emails
到一个名为 $vars
的数组中,但随后我得到了错误:
"Undefined variable $vars" on Line 14 of C:\...\SendMail.php
所以,我意识到问题似乎是我无法将任何变量传递给 Mail::send()
,或者换句话说,我只是不知道如何...
任何帮助将不胜感激...
托马斯·亚马凯蒂斯
您需要按如下方式传递 $emails 变量:
class SendMail {
public static function sendPost($post, $emails)
{
Mail::send('acme.blog::mail.message', $post, function($message) use ($emails) {
$message->to($emails);
$message->from('mail@compuflexcorp.com', 'Compuflex Mail');
$message->subject($post['subject']);
$message->replyTo($post['email']);
});
}
}
我正在尝试将 SAME 电子邮件发送到数组中给出的 多个 地址$emails
.
我创建了一个名为 SendMail
的 class,里面是一个接受 2 个参数的 sendPost()
方法:
($post, $emails)
这是我的代码:
class SendMail {
public static function sendPost($post, $emails)
{
Mail::send('acme.blog::mail.message', $post, function($message) {
$message->to($emails);
$message->from('mail@compuflexcorp.com', 'Compuflex Mail');
$message->subject($post['subject']);
$message->replyTo($post['email']);
});
}
}
问题是,我一直收到错误消息:
"Undefined variable $emails" on Line 14 of C:\...\SendMail.php
第 14 行:$message->to($emails);
我尝试过的:
我查看是否可以访问
sendPost()
的$post
和$emails
变量 inside,但是Mail::send()
之外。答案是 YES,我可以访问$post
和$emails
里面的信息sendPost()
],所以变量实际上被传递给了sendPost()
方法。一开始,我认为这与
$emails
不是Mail::send()
的参数之一有关,所以我把$post
和$emails
到一个名为$vars
的数组中,但随后我得到了错误:
"Undefined variable $vars" on Line 14 of C:\...\SendMail.php
所以,我意识到问题似乎是我无法将任何变量传递给 Mail::send()
,或者换句话说,我只是不知道如何...
任何帮助将不胜感激... 托马斯·亚马凯蒂斯
您需要按如下方式传递 $emails 变量:
class SendMail {
public static function sendPost($post, $emails)
{
Mail::send('acme.blog::mail.message', $post, function($message) use ($emails) {
$message->to($emails);
$message->from('mail@compuflexcorp.com', 'Compuflex Mail');
$message->subject($post['subject']);
$message->replyTo($post['email']);
});
}
}