2017-09-08 42 views
0

如何連接多個文件動態地laravel郵寄

Mail::send('emails.welcome', $data, function($message) 
 
{ 
 
    $message->from('[email protected]', 'Laravel'); 
 

 
    $message->to('[email protected]')->cc('[email protected]'); 
 

 
    $message->attach($pathToFile); 
 
});

當我寫這$ MESSAGE->附加($ pathToFile)foreach循環;然後我得到錯誤取消定義的foreach:

Mail::send('emails.welcome', $data, function ($message) { 
    $message->from('[email protected]', 'Laravel'); 
    $message->to('[email protected]')->cc('[email protected]'); 
    foreach ($this->quote_fileattache_results as $key => $value) { 
     $message->attach(public_path('/upload/quote/') . $value->filen‌​ame); 
    } 
}); 
+0

你可以在你想要使用foreach的地方顯示代碼嗎? –

+0

Mail :: send('emails.welcome',$ data,function($ message) { $ message-> from('[email protected]','Laravel'); $ message-> to '[email protected]') - > cc('[email protected]'); foreach($ this-> quote_fileattache_results as $ key => $ value){ $ message-> attach(public_path('/上傳/報價/').$值 - >文件名); } }); – Divyesh

+0

@Divyesh請修改您的問題 –

回答

0

你可以嘗試像下面連接多個文件

Mail::send('emails.welcome', $data, function($message) use ($pathToFile) 
{ 
    $message->from('[email protected]', 'Laravel'); 

    $message->to('[email protected]')->cc('[email protected]'); 

    for ($i=0; $i < count($pathToFile); $i++) { 
     $message->attach($pathToFile[$i]); 
    } 
}); 

希望這會有所幫助。