这可能是一些愚蠢的事情,但我不能让我的联系表格上的按钮开火或做任何事情。我已多次更改表单上的操作。我甚至没有得到错误,只是没有。我是PHP和Laravel的新手。
我的表格(在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="message" placeholder="Message" maxlength="140" rows="7"></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="button" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
</form>
我的路线(web.php):
Route::get('/', function () {
return view('welcome');
});
Route::post('/email/send', 'ContactEmailController@send');
我的电子邮件/ send.blade.php文件:
<html>
<head></head>
<body style="background: black; color: white">
<h1>{{$title}}</h1>
<p>{{$content}}</p>
</body>
</html>
我的App \ Mail \ ContactMailer:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ContactMailer extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('examplefrom@gmail.com')
->view('view.email.send');
}
}
我的ContactEmailCOntroller.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mail\ContactMailer.php;
class ContactEmailController extends Controller
{
public function send(Request $request)
{
$title = $request->input('title');
$content = $request->input('content');
Mail::send('emails.send', ['title' => $title, 'content' => $content], function ($message)
{
$message->from('examplefrom@gmail.com', 'My Laravel Email!');
$message->to('exampleto@gmail.com');
});
return response()->json(['message' => 'Request completed']);
}
}
答案 0 :(得分:0)
试试这个
<button type="submit" class="btn btn-primary pull-right">Submit Form</button>