Laravel 5.1 - 邮件附件 - fopen(...) 无法打开流:没有这样的文件或目录
Laravel 5.1 - Mail Attachments - fopen(...) failed to open stream: No such file or directory
当我尝试使用 Mail::later
发送带有附件的电子邮件时,我收到此错误:
fopen(../public/Asesorias/a.txt)
: failed to open stream: No such file or directory
这是我的代码:
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');
});
这是我的文件路径:ProjectName\public\Asesorias\a.txt
PS:在我的实际代码中,我使用了真实的电子邮件地址。
构建文件路径时使用public_path()
助手:
$message->attach(public_path('Asesorias/a.txt'));
当我尝试使用 Mail::later
发送带有附件的电子邮件时,我收到此错误:
fopen(../public/Asesorias/a.txt)
: failed to open stream: No such file or directory
这是我的代码:
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');
});
这是我的文件路径:ProjectName\public\Asesorias\a.txt
PS:在我的实际代码中,我使用了真实的电子邮件地址。
构建文件路径时使用public_path()
助手:
$message->attach(public_path('Asesorias/a.txt'));