1
I’m making a page to work with us with uploading files(resumes), I would like to send this file by email attachment, but I’m kind of aimless. Can someone help me?
Controller
public function trabalheConosco(RequestNewsletter $request)
{
$data['nomeDaEmpresa'] = "Arantes Nutrição Animal";
$data['nomeTrabalhe'] = $request->input("nomeTrabalhe");
$data['sobrenome'] = $request->input("sobrenome");
// $data['anexo'] = $request->input("anexo");
$data['emailTrabalhe'] = $request->input("emailTrabalhe");
$data['dataDeNascimento'] = $request->input("dataDeNascimento");
$data['area'] = $request->input("area");
$data['mensagemTrabalhe'] = $request->input("mensagemTrabalhe");
date_default_timezone_set('America/Sao_Paulo');
$date = date('Y-m-d H:i');
$data['dataDeEnvio'] = $date;
Mail::send('emails.trabalhe', $data, function($message){
$message->to('[email protected]', 'Teste')
->subject('Currículo');
$message->attach($anexo);
});
$request->session()->flash('alert-success', 'Currículo cadastrado com sucesso.');
return redirect('trabalhe-conosco');
}
View
<form action="{{ url('trabalhe-conosco') }}" method="POST" class="row">
{{ csrf_field() }}
<div class="form-group col-sm-12">
<p><strong>Dados Pessoais</strong></p>
</div>
<div class="form-group col-sm-4" {{ $errors->has('nomeTrabalhe') ? ' has-error' : '' }}>
<input type="text" name="nomeTrabalhe" class="form-control" placeholder="Nome: ">
@if ($errors->has('nomeTrabalhe'))
<span class="help-block">
<strong>{{ $errors->first('nomeTrabalhe') }}</strong>
</span>
@endif
</div>
<div class="form-group col-sm-5">
<input type="text" name="sobrenome" class="form-control" placeholder="Sobrenome: ">
</div>
<div class="form-group col-sm-3">
<input id="anexo" type="file" name="anexo" style="display: none"><label for='anexo' class="form-control" style="height: 48px;line-height: 35px;background-color: #a8cf45;">Anexar Currículo<i class="fa fa-paperclip" aria-hidden="true"></i></label></input>
</div>
<div class="form-group col-sm-3">
<input type="text" name="email" class="form-control" placeholder="E-mail: ">
</div>
<div class="form-group col-sm-4">
<input type="text" name="data_de_nascimento" class="form-control" placeholder="Data de Nascimento: ">
</div>
<div class="form-group col-sm-5">
<input type="text" name="area_de_interesse" class="form-control" placeholder="Área de Interesse: ">
</div>
<div class="form-group col-sm-12">
<textarea name="mensagem" class="animated form-control" rows="6" placeholder="Mensagem: "></textarea>
</div>
<div class="form-group col-sm-12">
<button class="btn btn-default">Enviar</button>
</div>
</form>
</div>
Requestnewsletter
public function messages()
{
return [
'emailnewsletter.required' => 'O campo Email é obrigatório.',
'emailnewsletter.email' => 'O campo Email deve ser um email válido',
'emailnewsletter.min' => 'O campo Email deve ter pelo menos :min caracteres.',
];
}
public function rules()
{
return [
'emailnewsletter' => 'required|email|min:7',
];
}
Route
Route::post('trabalhe-conosco', 'Front\MailController@trabalheConosco');
Make a tour by stackoverflow, learn a little about the rules and good practices. Then edit your question and enter the code of what you’ve tried...
– Marco Giovanni
How are you doing ? Do you have any code ?
Mail
of Laravel.– Diego Souza
I’m trying like this @Gumball
– Evandro Barbosa
Your form is without the attribute
enctype="multipart/form-data"
for sending files.– Diego Souza
Thanks @Gumball I’ll try
– Evandro Barbosa