普通网友 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 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能