Laravel邮件Swift_IoException无法打开文件进行读取

时间:2020-11-03 13:56:15

标签: php laravel email laravel-queue

这里有一个类似的问题:"Unable to open file for reading" (Swift_IoException) in Laravel Mailable

但是,接受的答案不能解决我的问题。 我还看到了documentation for attachments

我正在尝试在发送邮件时附加文件,这是我的代码。

 public function build()
    {
        $folder = public_path('/email');
        //Get a list of all of the file names in the folder.
        $files = glob($folder . '/*');
        //dd($files[]);
        
        
        if (!empty($files)) {
            return $this->subject($this->subject)->markdown('mail.newsletter')->with('data', $this->data)->attach(public_path('/email') . $files[0]);
        }else{
            return $this->subject($this->subject)->markdown('mail.newsletter')->with('data', $this->data);
        }
    }

程序进入if条件时出现此错误。

Swift_IoException 无法打开文件以读取[/home/riwaj/Desktop/Project/Library/public/email/home/riwaj/Desktop/Project/Library/public/email/attachment.jpg]

1 个答案:

答案 0 :(得分:0)

尝试在项目的根部执行此操作:

chmod -R 777 public