我在家庭控制器文件中创建了这个2功能
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Mail\Mailable;
use App\MediaBuzzPlayer;
use Illuminate\Support\Facades\View;
use App\MediaBuzzTeam;
use App\PerformanceBuzz;
use App\ArticleCategories;
use App\Fixture;
use App\Player;
use App\Page;
use App\ContactEmail as ContactEmail;
use Mail;
use Auth;
use DB;
class HomeController extends Controller {
public function getContact()
{
return view('contact-us');
}
public function postContact(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'message'=>'required'
]);
ContactEmail::create($request->only([
'name',
'email',
'message',
]));
$myEmail = 'shivangi.iihglobal@gmail.com';
Mail::to($myEmail)->send();
$notification = array(
'message' => 'Thanks! We shall get back to you soon.',
'alert-type' => 'success'
);
return redirect('home');
}
}
?>
当我提交联系我们页面邮件无法发送到我的电子邮件ID时,我当时有这种类型的错误
Type error: Argument 1 passed to Illuminate\Mail\PendingMail::send() must be an instance of Illuminate\Mail\Mailable, none given, called in /var/www/html/footyindexscout/app/Http/Controllers/HomeController.php on line 343
请帮助我,因为我是laravel的新手
答案 0 :(得分:0)
Try Mail::send('view name', ['data'=>$data], function($message)
{
$message->to('test@gmail.com', 'Email Message')->subject('Enquiry From Page!');
});
它对我有用
答案 1 :(得分:0)
您应该创建Mailable对象的子对象并将其作为参数发送到Mail :: send()方法