1

I've tried this to attach file in storage to a mail:

$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);
});

But I get this result:

ErrorException Undefined variable: HOR_IMG

WHat is wrong, and how could I make this work ?

Christophe
  • 68,716
  • 7
  • 72
  • 138

1 Answers1

0

You forgotten to add the $HOR_IMG & $NIC_IMG to the use of the closure passed to Mail::send, below the updated code.

$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);
});

In case it's not clear what use does I'd like to redirect you to this excellent answer: https://stackoverflow.com/a/1065197/1580028.

Alex
  • 1,425
  • 11
  • 25