[英]why my laravel is not sending form data in email
i am trying to send this data to email我正在尝试将此数据发送到电子邮件
dynamic_email_template.blade.php dynamic_email_template.blade.php
<p>Hi, This is {{ $data['name'] }}</p>
<p>I have some query like {{ $data['message'] }}.</p>
<p>It would be appriciative, if you gone through this feedback.</p>
but problem is that $data['name']
& $data['message']
is missing in received email但问题是收到的电子邮件中缺少$data['name']
& $data['message']
in model and controller even i am receiving this data i have checked it using dd($this->data)
here is my route在模型和控制器中,即使我收到了这些数据,我也使用dd($this->data)
检查了它,这是我的路线
Route::get('/sendemail', 'SendEmailController@index');
Route::post('/sendemail/send', 'SendEmailController@send')->name('send.mail');
my controller我的控制器
public function send(Request $request)
{
$data = array(
'name' => $request->name,
'message' => $request->message
);
// dd($data);
Mail::to('hamzaqureshi401@gmail.com')->send(new SendMail($data));
return back()->with('success', 'Thanks for contacting us!');
}
my model我的模特
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $data;
public function __construct($data)
{
$this->data = $data;
}
public function build()
{
dd($this->data);
return $this->from('scoops@creamery.pk')->subject('New Customer Equiry')->view('dynamic_email_template')->with('data', $this->data);
}
}
?>
where i am doing mistake any help will be thankfull我在哪里做错了任何帮助都会很感激
if you want you can try in dynamic_blade如果你愿意,你可以试试 dynamic_blade
<p>Hi, This is {{ $name }}</p>
<p>I have some query like {{ $email }}.</p>
<p>It would be appriciative, if you gone through this feedback {{ $message1 }}.</p>
and only use controller except using model class并且只使用控制器,除了使用模型类
$data = array(
'name' => $request->name,
'email' => $request->email,
'message1' => $request->message
);
Mail::send('dynamic_email_template',$data, function ($message) {
$message->from('example@mail.com', 'Contact');
$message->to('example@mail.com')->subject('Contact');
});
return back()->with('success', 'Thanks for contacting us!');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.