我有一个问题是将已经在pdf系统中创建的官方信件附加到数据库中的讲师电子邮件中。
公共功能批准($ id,请求$请求) {
try {
$letter = Letter::where('id',$id)
->update([
'isApproved' => 1,
'approvedBy' => $request->session()->get('users.id')
]);
$letter = Letter::where('id',$id)
->first();
$lecturer = User::where('id',$letter->user_id)
->get();
$emailBody="Hello, ".$lecturer[0]->username.",<br>".
"Your letter have been approved by ".$request->session()->get('users.username').".<br>".
"Kindly check the attachment. Thank you.<br><br>".
"This is system generated email. Please do-not reply on this email.";
mail($lecturer[0]->email, "Certification Approved", $emailBody);
return redirect()
->back()
->with('success_approve_letter','Record successfully approve');
} catch (Exception $e) {
return redirect()
->back()
->withErrors(["Error: ".$e->getMessage()]);
}
}
但是在电子邮件中,它只是发送它。
答案 0 :(得分:0)
请通过link通过php mail()发送附件,或者使用laravel email library发送电子邮件,这很容易
答案 1 :(得分:0)
Laravel方式是使用Mailables。从the docs附加PDF文件的示例:
$tests1 = \App\Task::withCount(['taskvisit' => function ($query) use ($a,$b){
$query->whereBetween('date', array($a,$b));
}])->orderBy('taskvisit_count', 'desc')->paginate(1000000);
public function taskvisit()
{
return $this->belongsToMany(Visit::class)->withPivot('task_visit', 'visit_id');
}