How to redirect to another view after sending email?

1

In the code below, after sending the form via email, the same view is loaded. Instead, I need to be directed to another view . (thanks for example)

Below is the code:

public function duvidas_e_contatos() {
    $this->load->helper('form');
    $this->load->library('form_validation');
    // REGRA DE VALIDAÇÃO
    $this->form_validation->set_rules('firstname', 'Nome', 'trim|required');
    $this->form_validation->set_rules('lastname', 'Sobrenome', 'trim|required');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('mobilephone', 'Celular', 'trim|required');
    $this->form_validation->set_rules('country', 'País', 'trim|required');
    $this->form_validation->set_rules('subject', 'Motivo do Contato', 'trim|required');
    $this->form_validation->set_rules('coment', 'Mensagem', 'trim|required');
    $this->form_validation->set_error_delimiters('<small class="text-danger">', '</small>');

    $infoPage['form_error']     = validation_errors();
        $infoPage['title']          = '';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = ''

    if ($this->form_validation->run() == FALSE) {
        $infoPage['form_error']     = validation_errors();
        $infoPage['title']          = '';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = '';

        $this->load->view('duvidas_e_contatos', $infoPage);

    } else {
        $formrequest = $this->input->post();
        date_default_timezone_set('America/Sao_Paulo');
        $this->load->library('email');
        $this->email->set_newline("\r\n");
        $this->email->initialize();

        $formrequest = $this->input->post();

        $subject = $formrequest['subject'];

        $mensagem_firstname     = $formrequest['firstname'];
        $mensagem_lastname      = $formrequest['lastname'];
        $mensagem_email         = $formrequest['email'];
        $mensagem_mobilephone   = $formrequest['mobilephone'];
        $mensagem_country       = $formrequest['country'];
        $mensagem_subject       = $formrequest['subject'];
        $mensagem_coment        = nl2br($formrequest['coment']);

        $message = "html";

        $body = $message;

        $result = $this->email
                ->from('')
                ->reply_to($formrequest['email'], $formrequest['firstname'])
                ->to('')
                ->cc('')
                ->bcc($formrequest['email'])
                ->subject($subject)
                ->message($body)
                ->send();

        $infoPage['firstname']      = $formrequest['firstname'];
        $infoPage['lastname']       = $formrequest['lastname'];
        $infoPage['email']          = $formrequest['email'];
        $infoPage['mobilephone']    = $formrequest['mobilephone'];
        $infoPage['country']        = $formrequest['country'];
        $infoPage['subject']        = $formrequest['subject'];
        $infoPage['coment']         = $formrequest['coment'];

        $infoPage['title']          = 'Confirmação de Contato';
        $infoPage['description']    = '';
        $infoPage['keywords']       = '';
        $infoPage['canonical']      = '';
        $infoPage['subtitle']       = 'Sua mensagem foi recebida!';
        $infoPage['autor']          = '';
        $infoPage['webmaster']      = '';
        $infoPage['credits']        = '';

        $this->load->view('mensagem_enviada', $infoPage);
    }
}
    
asked by anonymous 22.08.2017 / 20:20

1 answer

3

A cool way would be to change where you call:

$this->load->view('mensagem_enviada', $infoPage);

And use it this way:

if ($result)
{
     redirect('/aondequiser', 'refresh');
}

Remembering that for this you will need the url hello loader:

$this->load->helper('url');
    
22.08.2017 / 20:37