普通网友 2016-08-05 07:43
浏览 267
已采纳

在laravel中邮件,我想发送包含多个收件人的电子邮件

I have a problem here.. i try to send email to multiple recepients. The recepients are from my database which name of table is subscribes the message error is like this

ErrorException in SimpleMessage.php line 297:
Illegal offset type
public function store_job(Request $request)
    {
        $this->validate($request, ['posisi' => 'required','persyaratan' => 'required','tanggung_jawab' => 'required']);

        $tambah = new jobs(); //kita buat objek yang terhubung ke table JOBS
        $tambah->posisi = $request['posisi'];
        $tambah->persyaratan = $request['persyaratan'];
        $tambah->tanggung_jawab = $request['tanggung_jawab'];
        $tambah->kategori = $request['kategori'];
        $tambah->save();


        $anu = DB::table('subscribes')->select('email');
        $data = array ('email'=>$anu);
        Mail::send('emails.news', $data, function ($message) use ($request, $data) {
        $message->from('stevanajja@gmail.com',$request->email);     
        $message->to($data['email'])->subject($request->posisi);;
        });
        return redirect()->to('/panel_admin/opportune');
    }

please help as fast as possibble.. because i am a student, this is my homework for examination.

  • 写回答

2条回答 默认 最新

  • drxv39706 2016-08-05 07:54
    关注

    Here what I'am doing is declaring a new array $emails to store all email from database. By iterating the retrieved object anu, I am pushing the email to $emails and passing it to the to property of the mail.

        $anu = DB::table('subscribes')->select('email')->get();
        $emails=[];
        foreach($anu as $a){
             $emails[]=$a->email;
        }
        Mail::send('emails.news', $emails, function ($message) use ($request, $emails) {
        $message->from('stevanajja@gmail.com',$request->email);     
        $message->to($emails)->subject($request->posisi);;
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵