Laravel 5.1 - 邮件附件 - fopen(...)无法打开流:没有这样的文件或目录

时间:2015-08-13 19:33:26

标签: php email laravel laravel-5.1

当我尝试使用soup = BeautifulSoup(html_doc, 'xml') all_findings = soup.find_all('div', class_=re.compile(r'common text sighting_\d{5}')) print all_findings 发送带有附件的电子邮件时,我收到此错误:

  

Mail::later:无法打开流:没有此类文件或目录

这是我的代码:

fopen(../public/Asesorias/a.txt)

我知道这一定是一个愚蠢的问题,但我试图改变文件路径,但我找不到解决方案。

当我尝试使用Mail::later(5, 'emails.test', ['testVar' => 'hello'], function ($message){ $message->to('someaddress@hotmail.com', 'Someone'); $message->subject('Hello'); $message->attach('../public/Asesorias/a.txt'); }); 发送带有附件的电子邮件时,它运作正常:

Mail::send

这是我的文件路径:Mail::send('emails.test', ['testVar' => 'hello'], function ($message){ $message->to('someaddress@hotmail.com', 'Someone'); $message->subject('Hello'); $message->attach('../public/Asesorias/a.txt'); });

PS:在我的实际代码中,我使用了真实的电子邮件地址。

1 个答案:

答案 0 :(得分:3)

在构建文件路径时使用public_path()帮助程序:

$message->attach(public_path('Asesorias/a.txt'));