普通网友 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条)

报告相同问题?

悬赏问题

  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务启动失败
  • ¥15 用html创建一个个人网页,提供网页页面
  • ¥20 java项目连接SqlServer数据库报错
  • ¥15 基于面向对象的图书馆借阅管理系统
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥20 centos linux 7.9安装php8.2.18不支持mysqli模块的问题
  • ¥15 stata空间计量LM检验
  • ¥15 NAO机器人说出txt文本内容
  • ¥15 关于k8s node节点被释放后如何驱逐节点并添加新节点