gpt4 book ai didi

php - 在 Laravel 中使用 php 变量发送邮件

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:07:50 24 4
gpt4 key购买 nike

伙计们,我的 Controller 中有这段代码:

$name       =   Input::get('fname')." " .Input::get('lname');
$message = Input::get('message');
$email = Input::get('email');
$subject = Input::get('subject');
$phone = Input::get('phone');
$area = \App\Area::find(1)->name;
$ticket = \App\Area::find(1)->ticket_sent;
Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message)
{
$message->from('asd@gmail.com', 'Name');
$message->to('support@mycompany.it');
$message->subject('Support');

});
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');

效果很好,但我正在尝试更改以下两行:

$message->from($email, $name);
$message->subject($subject);

但它不起作用。我究竟做错了什么?我不明白。

最佳答案

请检查代码,需要在"function ($message)"后面加上use

$name      =   Input::get('fname')." " .Input::get('lname');
$message = Input::get('message');
$email = Input::get('email');
$subject = Input::get('subject');
$phone = Input::get('phone');
$area = \App\Area::find(1)->name;
$ticket = \App\Area::find(1)->ticket_sent;

Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message) use ($email, $name,$subject)
{
$message->from($email, $name);
$message->to('support@mycompany.it');
$message->subject($subject);
});
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');

关于php - 在 Laravel 中使用 php 变量发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39247017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com