普通网友 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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题