我试图在Laravel中使用Mailable,我遇到了一个我之前没有遇到过的问题,目前似乎没有什么可以提供帮助.
在开发一个新的Mailable时,除了将一个EXISTING文件附加到mailable之外,我还能正常工作.
错误返回如下:
"message": "Unable to open file for reading [/public/storage/shipments/CJ2K4u6S6uluEGd8spOdYgwNkg8NgLFoC6cF6fm5.pdf]",
"exception": "Swift_IoException",
"file": "E:\\webserver\\htdocs\\truckin\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\ByteStream\\FileByteStream.PHP",
"line": 131,
但是如果你浏览文件夹和文件,实际上有一个文件,我可以打开它,我甚至可以通过ajax弹出窗口打开它来查看详细信息.
这是我的邮寄:
<?PHP
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Shipment;
use App\Shipment_Attachment;
class shipmentAttachments extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $shipment, $attachment, $storagePath;
public function __construct($shipment, $attachment, $storagePath)
{
$this->shipment = $shipment;
$this->attachment = $attachment;
$this->attachmentFile = '/public'.$storagePath;
$this->proNumber = $shipment->pro_number;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('billing@cmxtrucking.com')
->cc('billing@cmxtrucking.com')
->subject('New Attachment(s) - '. $this->proNumber)
->view('emails.shipments.shipmentAttachments',['shipment'=> $this->shipment])
->attach($this->attachmentFile);
}
}
这是我的控制器导致mailable:
public function attachmentsEmail(Request $request){
$shipment = Shipment::findOrFail($request->shipmentID);
$attachment = Shipment_Attachment::findOrFail($request->attachmentID);
$storagePath = Storage::url($attachment->attachmentPath);
$email = $request->email;
Mail::to($email)->send(new shipmentAttachments($shipment, $attachment, $storagePath)); //maybe try to use queue instead of send...
return back();
}
所以我不确定这可能来自哪里.
解决方法:
尝试使用public_path()laravel helper函数而不是’/ public’.
$this->attachmentFile = public_path() . '/' . $storagePath;
也许您需要在public / index.PHP中更改此变量.我正好在require bootstrap下面:
$app->bind('path.public', function() {
return __DIR__;
});
做一些测试.
dd(public_path());
dd(public_path() . '/' . $storagePath);
希望这对你有所帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。