我有Homecontroller
public function contactsform()
{
$siteemail = 'adm.alisher@gmail.com'; $input = request()->all();
$this->validate(request(), [
'name' => 'required',
'email' => 'required|email',
'phone' => 'required',
]);
if (request()->file('file') == null)
{
$file = "";
}else
{
$file = request()->file('file')->store('public/uploads');
}
if(!empty(request('file')))
{
$input['file'] = $file;
}
// dd($input['file']);
\Mail::to($siteemail)
->send(new Contact($input));
// return response()->json(['msg' => request('name')]);
return view('welcome');
}
App \ Mail \ Sendfile
public function build()
{
// return $this->view('view.name')->attach('/path/to/file');if(array_key_exists('file', $this->input) && strlen($this->input['file']) > 1)
{
Storage::setVisibility($this->input['file'], 'public');
return $this->subject('Поваренок | Онлайн форма')
->from('sitename@example.com')
->view('emails.contact')
->attach(env('APP_URL').Storage::url($this->input['file']));
}
else {
return $this->subject('Поваренок | Онлайн форма')
->from('sitename@example.com')
->view('emails.contact');
}
}
但是我想发送文件电子邮件。对不起大家。请帮我 前面
<form action="/contactsform" method="POST" enctype="multipart/form-data">
@csrf
<div class="order_form flex">
<div class="flex input_block">
<input type="text" name="name" class="order_input" placeholder="Имя*" required="">
<input type="text" class="order_input" id="phone2" name="phone" placeholder="Телефон*" maxlength="20" required="">
<input type="text" class="order_input" name="email" placeholder="E-mail" maxlength="20" required="">
</div>
<div class="form_send">
<textarea placeholder="Задайте вопрос" name="text"></textarea>
<div class="flex add_block">
<div class="add add_file"><input type="file" value="Прикрепить файл" name="file"></div>
<div class="add add_txt"><span>Вы можете прикрепить файл заявке до 10 мб</span></div>
</div>
<div class="form_send_btn"><button type="submit" class="sub">Оставить заявку</button></div>
</div>
</div>
</form>
答案 0 :(得分:1)
您的文件路径有问题。
您将文件路径附加为不正确的URL
附件采用文件的绝对路径。
return $this->subject('Поваренок | Онлайн форма')
->from('sitename@example.com')
->view('emails.contact')
->attach(Storage::path($this->input['file']));