我有角度app作为前端和laravel 5.2作为api后端。我的角度应用程序将参数发送到我的laravel控制器:
{
name: "My Name",
email: "example@email.com",
subject: "Hello",
message: "This My Message",
attachment: {
base64: /9j/4AAQSkZJRgABAQEASABIAAD/2wCEAAMCAgMC.....
filetype: "application/rar",
filename: "example.rar",
filesize: 198141,…
}
}
在我的laravel控制器中,我有这样的代码
$data = [
'name' => $request->input('name'),
'email' => $request->input('email'),
'subject' => $request->input('subject'),
'message' => $request->input('message'),
'attachment' => $request->file('attachment'),
'store' => 'Store Name',
];
Mail::send('emails.call-us', ['data' => $data],
function ($m) use ($data) {
$m->from($data['email'], $data['name'] . ' - ' . $data['store']);
$m->attach($data['attachment'], [as => 'example.rar', ['mime' => 'application/rar']);
$m->to(env('EMAIL_CONTACT_US'));
$m->subject($data['subject']);
});
从base64格式发送文件作为附件电子邮件的推荐方法是什么?感谢
答案 0 :(得分:0)
好的,我解决了我的问题,很容易......
刚刚更改了附加到attachData
$data = [
'name' => $request->input('name'),
'email' => $request->input('email'),
'subject' => $request->input('subject'),
'message' => $request->input('message'),
'attachment' => $vAttachment,
'store' => $vStore->name,
];
Mail::send('emails.call-us', ['data' => $data],
function ($m) use ($data) {
$m->from($data['email'], $data['name'] . ' - ' . $data['store']);
$m->attachData(base64_decode($data['attachment']['base64']), $data['attachment']['filename'], ['mime' => $data['attachment']['filetype']]);
$m->to(env('EMAIL_CONTACT_US'));
$m->subject($data['subject']);
傻傻的我:)。