问题
How to add email attachment in laravel? And the download link on that,and also to validate just the PDF and size is no longer up to 2mb. Sorry im just a student that love to code. Please help me.
This is my controller code
public function store_applier(Request $request)
{
$this->validate($request, [
'nama' => 'required',
'email' => 'required',
'kontak' => 'required',
'kategori'=>'required',
'posisi' => 'required',
'alamat' => 'required',
]);
$tambah = new appliers(); //kita buat objek yang terhubung ke table JOBS
$tambah->nama = $request['nama'];
$tambah->email = $request['email'];
$tambah->kontak = $request['kontak'];
$tambah->kategori = $request['kategori'];
$tambah->posisi = $request['posisi'];
$tambah->alamat = $request['alamat'];
$file = $request->file('upload_cv');
$fileName = $file->getClientOriginalName();
$request->file('upload_cv')->move("cv/", $fileName);
$tambah->upload_cv = $fileName;
$tambah->save();
$email = DB::table('user')->where('email');
Mail::send('emails.welcome', [
'email' => $request['email'],
'HP' => $request['kontak'],
'nama' => $request['nama'],
'posisi' => $request['posisi'],
'CV' => $tambah->upload_cv = $fileName
], function ($message) use ($request, $tambah, $email) {
$message->from('stevanajja@gmail.com', $request->posisi);
$message->to('stevantinusl47@gmail.com')
->subject('Lamaran Baru')
->cc('stevanlai@yahoo.com.sg')
->replyTo($request->email);
$message->getSwiftMessage();
});
return redirect()->to('index');
}
and this is the view code
**<h1>Lamaran Baru</h1>
From : {{ $email }}
<br />
NO.HP : {{$HP}}
<br />
=========================
<br /><br />
Nama saya {{ $nama }},
<br /><br />
Saya ingin melamar pekerjaan di PT.Halcom dengan posisi sebagai
<h2>{{$posisi}}</h2>
<br />
Berikut saya lampirkan CV saya
<br /><br /><br />
*Klik link dibawah untuk melihat CV
<br />
<a href="{!!URL::asset('../cv/{{$CV}}')!!}">KLIK</a>**
sorry for my bad to wasting ur time to answer the stupid question.. i am just student
回答1:
Add attach
method in your message chain.
$message->to('stevantinusl47@gmail.com')
->subject('Lamaran Baru')
->cc('stevanlai@yahoo.com.sg')
->replyTo($request->email)
->attach('path_to_pdf_file', [
'as' => 'your-desired-name.zip',
'mime' => 'application/pdf'
]);
For your path
<a href="{{ asset('path-to-your-pdf-in-public-directory') }}">KLIK</a>
来源:https://stackoverflow.com/questions/38820830/laravel-mail-attachment