我正在联系表格。 如果有人填写表格,则应将数据(文本,主题)发送到我的邮箱。 一切正常,但当我填写表单并发送电子邮件时,它会发送整个HTML页面(而不仅仅是表单中的文本)。
这是它的样子
这是我发送邮件的控制器
public function sendEmail(Request $request) { $data["username"] = $request->username; $data["email"] = $request->email; $data["subject"] = $request->subject; $data["mail_text"] = $request->mail_text; Mail::send('contact', ["data" => $data], function ($mail) use ($data){ $mail->to("leribobo@gmail.com")->from($data["email"])->subject($data["subject"]); }); return redirect()->back(); }因为我猜它会发送'contact'页面,这是方法中的第一个参数
Mail::send('contact' ....I'm making a contact form. If someone fills in the form, the data (text,subject) should be sent to my mail. Everything works, but when I fill in form and send the email, it sends the whole HTML page (not just the text from the form).
Here's how it looks like
Here's my controller where I send the mail
public function sendEmail(Request $request) { $data["username"] = $request->username; $data["email"] = $request->email; $data["subject"] = $request->subject; $data["mail_text"] = $request->mail_text; Mail::send('contact', ["data" => $data], function ($mail) use ($data){ $mail->to("leribobo@gmail.com")->from($data["email"])->subject($data["subject"]); }); return redirect()->back(); }as I guess it sends 'contact' page, which is first parameter in method
Mail::send('contact' ....最满意答案
您实际上正在发送contact.blade.php文件。 这不是我们应该如何发送邮件。
Mail::send('emails.contact', $data, function ($message) { // $message->from('us@example.com', 'Laravel'); $message->to('foo@example.com')->cc('bar@example.com'); });您必须在emails.contact.blade.php创建一个文件,并将$data传递给刀片文件,如上所示。
点击此处: https : //laravel.com/docs/5.1/mail#sending-mail
You are actually sending the contact.blade.php file. This is not how we should send a mail.
Mail::send('emails.contact', $data, function ($message) { // $message->from('us@example.com', 'Laravel'); $message->to('foo@example.com')->cc('bar@example.com'); });You've to make a file in emails.contact.blade.php and pass $data to the blade file as showed above.
Check here: https://laravel.com/docs/5.1/mail#sending-mail
更多推荐
发布评论