如何将存储中的文件附加到邮件-Laravel 6

时间:2020-01-12 15:05:06

标签: php laravel

我已经尝试过将存储中的文件附加到邮件:

$attachments = OnlineReply::where('ContactNo', $ContactNo)->first() ; 
$HOR_IMG= '/home/sameera/Desktop/sewa/sewa/public/storage/'.$attachments['HOR_IMG'];
$NIC_IMG= '/home/sameera/Desktop/sewa/sewa/public/storage/'.$attachments['NIC_IMG'];

//dd($HOR_IMG,$NIC_IMG);         

Mail::send('mail.CRepliesSend',$data, function($message) use ($to_name,$to_email)
{   $message->to($to_email)->subject('reply for your add on mangala sewa'); 
    $message->attach($HOR_IMG);
    $message->attach($NIC_IMG);
});

但我得到以下结果:

ErrorException 未定义的变量:HOR_IMG

WHat是错误的,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您忘记将$HOR_IMG$NIC_IMG添加到传递给use的闭包的Mail::send中,位于更新后的代码下方。

$attachments = OnlineReply::where('ContactNo', $ContactNo)->first() ; 
$HOR_IMG= '/home/sameera/Desktop/sewa/sewa/public/storage/'.$attachments['HOR_IMG'];
$NIC_IMG= '/home/sameera/Desktop/sewa/sewa/public/storage/'.$attachments['NIC_IMG'];

//dd($HOR_IMG,$NIC_IMG);         

Mail::send('mail.CRepliesSend',$data, function($message) use ($to_name,$to_email,$HOR_IMG,$NIC_IMG)
{   $message->to($to_email)->subject('reply for your add on mangala sewa'); 
    $message->attach($HOR_IMG);
    $message->attach($NIC_IMG);
});

如果不清楚use是什么,我想将您重定向到这个出色的答案:https://stackoverflow.com/a/1065197/1580028