我正在尝试使用Laravel函数Mail发送附件,但是它不起作用,它显示了下一个错误:
传递给Swift_Mime_SimpleMessage :: attach()的参数1必须实现接口Swift_Mime_MimeEntity,给定的字符串,在第640行的/home/jysparki/public_html/app/Http/Controllers/BillController.php中调用并定义
我的代码就是这个:
$email = Email::find(22);
$body = $email->email;
$client = Our_Client::find($invoice_history->id_client);
$search = array('$client_name', '$folio', '$amount', '$bill_date');
$replace = array($client->client, $invoice_history->folio, $invoice_history->amount, Helper::fixdate($invoice_history->bill_date));
$body = str_replace($search, $replace, $body);
$search = array('$folio');
$replace = array($invoice_history->folio);
$subject = $email->subject;
$subject = str_replace($search, $replace, $subject);
$data = array( 'email' => 'rodrigocabezas@jisparking.cl', 'subject' => $subject, 'body' => $body , 'file' => $file_url);
Mail::send([], $data, function ($message) use ($data) {
$message->to($data['email'])
->subject($data['subject'])
->setBody($data['body'], 'text/html') // for HTML rich messages
->attach($data['file'], ['as' => 'Your_Invoice.pdf', 'mime' => 'application/pdf']);
});
您怎么看我在这里传递文件:
->attach($data['file'], ['as' => 'Your_Invoice.pdf', 'mime' => 'application/pdf']);
此$ data ['file']包含文件的url,我对其进行了测试,可以在浏览器中显示该文件。
问题是什么?
谢谢