[英]Laravel contact form email will not show message after email is sent
I have a contact form which sends emails to Mailtrap. 我有一个联系表,可以将电子邮件发送到Mailtrap。 The name and the email content display in the email body, but not the message. 名称和电子邮件内容显示在电子邮件正文中,但不显示消息。 The following is my code: 以下是我的代码:
Contact form blade (welcome.blade.php): 联系表格刀片(welcome.blade.php):
<form role="form" method="POST" action="/email/send">
{{ csrf_field() }}
<br style="clear:both">
<h3 style="margin-bottom: 25px; text-align: center;">Contact Form</h3>
<div class="form-group">
<input type="text" class="form-control errorBorder" id="name" name="name" placeholder="Name">
<span id="warningLabel" class="warning wone" style="display:none;">Please enter name!</span>
</div>
<div class="form-group">
<input type="text" class="form-control" id="email" name="email" placeholder="Email" required>
<span id="warningLabel2" class="warning wtwo" style="display:none;">Please enter email!</span>
</div>
<div class="form-group">
<textarea class="form-control" type="textarea" id="query" placeholder="Message" maxlength="140" rows="7" name="message"></textarea>
<span id="warningLabel3" class="warning wthree" style="display:none;">Please enter message!</span>
<span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
</form>
My email template (send.blade.php): 我的电子邮件模板(send.blade.php):
<html lang="en">
<head></head>
<body style="background: black; color: white">
<h1>{!!$name!!}</h1>
<h1>{!!$email!!}</h1>
<p>{!!$query!!}</p>
</body>
</html>
And then my controller: 然后我的控制器:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Mail;
use Illuminate\Http\Request;
use App\Mail\ContactMailer;
class ContactEmailController extends Controller
{
public function send(Request $request)
{
$name = $request->input('name');
$email = $request->input('email');
$query = $request->input('query');
Mail::send('email.send', ['name' => $name, 'email' => $email, 'query' => $query], function($message){
$message->from('examplefrom@gmail.com', 'Example');
$message->to('Exampleto@gmail.com');
});
}
}
Try this in your controller 在您的控制器中尝试
public function send(Request $request)
{
$name = $request->name;
$email = $request->email;
$query = $request->message;
Mail::send('email.send', ['name' => $name, 'email' => $email, 'query' => $query], function($message){
$message->from('examplefrom@gmail.com', 'Example');
$message->to('Exampleto@gmail.com');
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.