[英]How to send a email when import?
I am trying send an email to a user, when a list is import.当导入列表时,我正在尝试将 email 发送给用户。
But is not working.但不工作。 I am Using Mailtrap.
我正在使用 Mailtrap。
This is my code here i think where is the problem:这是我的代码,我认为问题出在哪里:
<?php
namespace App\Http\Controllers;
use App\Imports\CsvImport;
use App\Mail\SuccessMail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Maatwebsite\Excel\Facades\Excel;
use function GuzzleHttp\Promise\all;
class CsvFile extends Controller
{
function index()
{
return view('csv_file');
}
public function csv_import()
{
Excel::import(new CsvImport, request()->file('file'));
return redirect('/home');
}
public function sendEmail()
{
$user = Auth::user();
Mail::to($user->email)->send(new SuccessMail());
}
}
You need to call sendEmail()
function from csv_import()
function:您需要从
csv_import()
function 调用sendEmail()
) function:
public function csv_import()
{
Excel::import(new CsvImport, request()->file('file'));
$this->sendEmail(); // then sendEmail function will execute
return redirect('/home');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.