虽然我检查了stackoverflow和其他方面的所有可用方法,但我根本无法收到任何邮件。 需要帮助解决它。
邮件配置良好,它发送其他邮件,如通过重置,验证码在同一个控制器!所有其他邮件都已送达,但主页上的联系表格并未发送任何邮件
<form method="post">
<div class="row">
<div class="col-lg-6">
<input type="text" name="firstname" id="firstname" placeholder="First Name*">
</div>
<div class="col-lg-6">
<input type="text" name="lastname" id="lastname" placeholder="Last Name*">
</div>
<div class="col-lg-12">
<input type="email" name="email" id="email" placeholder="Your Email*">
<textarea name="message" id="message" cols="30" rows="5" placeholder="Message"></textarea>
</div>
</div>
<input type="submit" id="conEmail" value="Send Now">
</form>
javascript
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','#conEmail',function(e){
e.preventDefault();
var email = $('#email').val();
var firstname = $('#firstname').val();
var lastname = $('#lastname').val();
var message = $('#message').val();
$.ajax({
type:'GET',
url:'{{ route('contactEmail') }}',
data:{email:email,firstname:firstname, lastname:lastname,
message:message},
success:function(data){
swal('success','Successfully Sent Email','success');
console.log(data);
},
error:function (error) {
var message = JSON.parse(error.responseText);
swal('error',message.errors.email,'error');
console.log(message.errors.email);
}
});
});
});
</script>
路线
Route::post('/contactEmail', 'FrontController@contactEmail')->name('contactEmail');
控制器
namespace App\Http\Controllers;
use App\Etemplate;
use App\Frontend;
use App\Http\Requests;
use Auth;
use Mail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class FrontController extends Controller
{
public function contactEmail(Request $request)
{
$this->validate($request,
[
'email' => 'required|email',
'firstname' => 'required',
'lastname' => 'required',
'message' => 'required'
]);
$temp = Etemplate::first();
$to = $temp->esender;
$name = $request->firstname.' '.$request->lastname;
$subject = 'User Email';
$message = 'Email From:'.$request->email.'<br/>'.$request->message;
send_email($to, $name, $subject, $message);
return back();
}
答案 0 :(得分:0)
只需更改此内容 - 您使用的是get而不是post
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','#conEmail',function(e){
e.preventDefault();
var email = $('#email').val();
var firstname = $('#firstname').val();
var lastname = $('#lastname').val();
var message = $('#message').val();
$.ajax({
type:'POST',
url:'{{ route('contactEmail') }}',
data:{email:email,firstname:firstname, lastname:lastname,
message:message},
success:function(data){
swal('success','Successfully Sent Email','success');
console.log(data);
},
error:function (error) {
var message = JSON.parse(error.responseText);
swal('error',message.errors.email,'error');
console.log(message.errors.email);
}
});
});
});
</script>