2017-05-13 41 views
1

我有角應用作爲前端和laravel 5.2作爲api後端。我的角應用程序發送參數到我的laravel控制器這樣的:如何將文件附加到Laravel 5.2郵件Base64格式

{ 
    name: "My Name", 
    email: "[email protected]", 
    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

好吧,我解決我的問題,很容易...

只是改變了重視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']); 

我傻:)

相關問題