我有这个片段,用我在env中设置的邮件枪API发送电子邮件。这一切都发送,但我现在想从用户中选择变量,并根据输入设置一些其他信息
$name = $request->name;
$name2 = 'hello';
$email = $request->email;
$message = $request->message;
Mail::raw($message, function($message)
{
$message->from('[email protected]', 'In-app Correspondence By -- ')->subject('Welcome!');
$message->to('[email protected]')->cc('[email protected]');
});
问题是当我把$message->to($email)->cc('[email protected]');
给出内部服务器错误,但上面的代码工作正常。
电子邮件很好我检查但是在那里。我还想回复邮件并插入$ email变量。到目前为止,回复甚至在主题上放置$ email都会导致内部服务器错误。
可能是什么问题。
如果要将变量传递给PHP中的闭包,则必须使用use
关键字。试试这个:
$name = $request->name;
$name2 = 'hello';
$email = $request->email;
$message = $request->message;
Mail::raw($message, function($message) use ($email)
{
$message->from('[email protected]', 'In-app Correspondence By -- ')->subject('Welcome!');
$message->to($email)->cc('[email protected]');
});