电子邮件在laravel 5.1中发送整个html页面(而不是电子邮件正文)(email sends whole html page(instead of email body) in laravel

编程入门 行业动态 更新时间:2024-10-26 02:37:16
电子邮件在laravel 5.1中发送整个html页面(而不是电子邮件正文)(email sends whole html page(instead of email body) in laravel 5.1)

我正在联系表格。 如果有人填写表格,则应将数据(文本,主题)发送到我的邮箱。 一切正常,但当我填写表单并发送电子邮件时,它会发送整个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

更多推荐

本文发布于:2023-07-29 20:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   而不是   页面   正文   laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!