【发布时间】:2020-01-04 10:11:26
【问题描述】:
我想通过导入excel 文件一次发送多封电子邮件。现在,我正在导入excel 文件并将数据作为数组保存到variable 中。
我正在使用maatwebsite/excel version 3.1。导入后,文件数据作为嵌套数组存储到变量中,excel 文件的其余列也保持空值。我尝试使用array_filter,但它不能正常工作。这是我现在得到的回复截图 - response in console
.
在 EmailsController 中 -
public function sendEmailUsingFileAndSave(Request $request)
{
//here is $content, $fromemail, $fromname etc..
$file = $request->file('file');
$import = new EmailsImport;
Excel::import($import, $file);
return $emails = $import->data;
foreach($emails as $email)
{
Mail::send('email.content', ['content' => $content], function($message)
use ($email, $subject, $fromemail, $fromname) {
$message->to($email)->subject($subject);
$message->from($fromemail, $fromname);
});
}
}
在app\imports 文件夹中EmailsImport.php 是-
<?php
namespace App\Imports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\WithValidation;
class EmailsImport implements ToCollection, WithValidation
{
use Importable;
public $data;
public function collection(Collection $rows)
{
$this->data = $rows;
}
}
我期待这样的回应 - (2) ["abc@example.com","xyz@example.com", "abc@another.com"]
我的导入示例 excel 文件是 - sample excel file
我一直在尝试这样做,有人可以帮我解决这个问题吗?
【问题讨论】:
-
看看this 线程。也许您的目标是进行验证
标签: php arrays laravel vue.js laravel-excel