Laravel 邮件附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38820830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Mail Attachment
提问by Stevan Lai
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.
如何在laravel中添加电子邮件附件?以及上面的下载链接,以及仅验证 PDF 和大小不再高达 2mb。对不起,我只是一个喜欢编码的学生。请帮我。
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('[email protected]', $request->posisi);
$message->to('[email protected]')
->subject('Lamaran Baru')
->cc('[email protected]')
->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
抱歉浪费你的时间来回答这个愚蠢的问题..我只是学生
回答by Zayn Ali
Add attach
method in your message chain.
attach
在您的消息链中添加方法。
$message->to('[email protected]')
->subject('Lamaran Baru')
->cc('[email protected]')
->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>