[英]Send mail in Laravel 5.4
我正在嘗試在Laravel 5.4中發送電子郵件,但我不斷收到錯誤消息“ 500內部服務器錯誤”
我想使用AJAX請求將電子郵件發送到控制器,然后從那里發送我想要的電子郵件。
這是我的.env文件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abdul.elah.js@gmail.com
MAIL_PASSWORD="My Email Password"
MAIL_ENCRYPTION=tls
我的ajax請求
$('#form').on('submit', function(e) {
e.preventDefault();
e.stopPropagation();
let data = $('#form').serialize();
let name = $('input[name=name]').val();
let phone = $('input[name=phone]').val();
let message = $('textarea[name=message]').val();
$.post('/create', data, function(data, textStatus, xhr) {
console.log(textStatus);
if (data.lang == '/en') {
$('.notification').css('left', '15px');
window.setTimeout(function() {
$('.notification').css('left', '-350px');
}, 5000);
} else {
$('.notification').css('right', '15px');
window.setTimeout(function() {
$('.notification').css('right', '-350px');
}, 5000);
}
$("input[name=name]").val('');
$("input[name=phone]").val('');
$("textarea[name=message]").val('');
});
})
我的web.php
Route::post('create', 'EnquiryController@send');
我的EnquiryController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Response;
use \App\Mail\Enquiry;
use Mail;
class EnquiryController extends Controller
{
public function send() {
// I tried this way and didn't work so i tried the one beneath
// Mail::to('abdul.elah.js@gmail.com')->send('emails.enquiry');
Mail::send('emails.enquiry', [], function($message) {
$message->to('abdul.elah.js@gmail.com')->subject('Test');
$message->from('abdul.elah.js@gmail.com', 'Abdul Elah');
});
return response()->json([ 'message' => 'Message Sent Successfully' ]);
}
}
並且我在resources/views/emails/enquiry.blade.php
有一個<h1> Hello World </h1>
的簡單html。
我的問題是瀏覽器不斷記錄500錯誤,而沒有任何可能對調試有用的數據。
問題很簡單,就是我沒有重新啟動服務器,猜測我在編輯.env文件后必須重新啟動服務器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.