我有一个联系表单,可以向Mailtrap发送电子邮件。电子邮件正文中显示名称和电子邮件内容,但不显示消息。以下是我的代码:
联系表格刀片(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>
我的电子邮件模板(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>
然后我的控制器:
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');
});
}
}
答案 0 :(得分:0)
在你的控制器中试试这个
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');
});
}