首页 > 解决方案 > 如何将存储中的文件附加到邮件 - laravel 6

问题描述

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

$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

出了什么问题,我怎么能做到这一点?

标签: phplaravel

解决方案


您忘记在更新后的代码下方将$HOR_IMG&添加$NIC_IMGuse传递给的闭包中。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 。


推荐阅读