Form (view):
<form action="<?php echo base_url(lang())?>/trabalhe-conosco/enviar" method="post" class="formulario-contato fonte-padrao-titulos" enctype="multipart/form-data">
<div class="col col-30 fl">
<label class="opacity">Hidden</label>
<div class="clearfix file-box">
<div class="fake-input"><?php echo set_value('userfile')?></div>
<label class="file-button-send <?php echo (form_error('userfile')) ? 'error' : '' ?>" for="userfile">
ANEXAR CURRÍCULO
<input class="hide<?php echo (form_error('userfile')) ? ' error' : '' ?>" type="file" name="userfile" id="userfile">
</label>
<?php echo form_error('userfile') ?>
</div>
</div>
<div class="col col-20 fr">
<label class="opacity">Hidden</label>
<input class="fonte-padrao-titulos black" type="submit" value="<?php echo $this->lang->line('botao_form'); ?>">
</div>
</form>
Controller:
defined('BASEPATH') OR exit('No direct script access allowed');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require getcwd() . '/vendor/autoload.php';
class TrabalheConosco extends Application_Controller {
public function index(){
$this->load->template("trabalhe-conoscoView",$this->data);
}
public function enviar(){
$this->load->helper("file_upload");
$config = array(
'upload_path' => getcwd() . '/upload/',
'allowed_types' => 'doc|docx|pdf',
'max_size' => 8196
);
$this->load->library('upload', $config);
$this->form_validation->set_rules('nome','Nome','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('telefone','Telefone','required');
$this->form_validation->set_rules('interesse','Área de Interesse','required');
$this->form_validation->set_error_delimiters("<span class='form-error'>","</span>");
if ($this->form_validation->run() == TRUE) {
$this->upload->do_upload('userfile');
$dados_form = $this->input->post();
$html = '<p>Nome: '.$dados_form["nome"].' '.$dados_form["sobrenome"].'</p>
<p>Email: '.$dados_form["email"].'</p>
<p>Telefone: '.$dados_form["telefone"].'</p>
<p>Área de Interesse: '.$dados_form["interesse"].'</p>';
$destino = '[email protected]';
$mail = new PHPMailer(true);
$mail->setFrom('[email protected]', 'RH'); //Name is optional
$mail->isHTML(true);
$mail->Subject = 'Trabalhe Conosco';
$mail->Body = $html;
$mail->addAddress($destino);
if (isset($_FILES) && $_FILES['userfile']['name'] !== '') {
$mail->AddAttachment($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name']);
}
if ($mail->send()) {
$this->session->set_flashdata('success','E-mail enviado com sucesso!');
redirect("pt/trabalhe-conosco");
}else{
$this->session->set_flashdata('error','Erro no envio. Tente novamente mais tarde!');
echo $this->email->print_debugger();
}
}else{
$this->load->template("trabalhe-conoscoView",$this->data);
}
}
}
Put the form code
– PaulinhoCaP
Okay, get down below.
– Eron Venter