【问题标题】:Multiple files view in email template laravel电子邮件模板 laravel 中的多个文件视图
【发布时间】:2020-04-19 19:00:04
【问题描述】:

我有一组图像路径可以附加到电子邮件中。如何在电子邮件模板中查看它们?

发送邮件控制器:

  $files = collect(json_decode($img_files))->map(function ($file) {
    return public_path('uploads' . DIRECTORY_SEPARATOR . $file->name);
  })->toArray();

  Mail::to($customer_email)->send(new SendMail($customer_firstname, $pathToFile), function($message){
        foreach ($files as $filePath) {
            $message->attach($filePath);
        }
      }
  );

在我的电子邮件模板中:

<img src="{{ $message->embed($filePath) }}" style="width:600px;height:335px">

但这给出了Undefined variable: filePath 错误。我怎么能这样

【问题讨论】:

    标签: php laravel email laravel-5 notifications


    【解决方案1】:

    试试这个方法。

    Mail::to($customer_email)->send(
        new SendMail($customer_firstname, $files), function($message){
            $size = sizeOf($files); //get the count of number of attachments 
    
            for ($i=0; $i < $size; $i++) {
                $message->attach($files[$i]);
            }
    
        }
    );
    

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 2021-08-31
      • 2011-05-21
      • 1970-01-01
      • 2017-08-17
      • 2013-12-11
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多