0

Hi there i am using a form submission but i want that i want to display contact page even after submission of the form. I dont want to view error or success page

this is my controller:

public function validate()
    {
        $name    = $this->input->post("name");
        $email   =$this->input->post("email");
        $captcha   =$this->input->post("captcha");
        $message =$this->input->post("message");
        $captcha_code     =$this->session->userdata("captcha_code");

        if($captcha == $captcha_code){
            $this->load->library("PHPMailer_Library");
        $objMail = $this->phpmailer_library->load();


        $mail = new PHPMailer(true);                              
        try {

        $mail->SMTPDebug = 2;                               
        $mail->isSMTP();                                      
        $mail->Host = 'smtp.gmail.com';  
        $mail->SMTPAuth = true;                               
        $mail->Username = 'proxyemu19@gmail.com';                 
        $mail->Password = '****';                           
        $mail->SMTPSecure = 'tls';                            
        $mail->Port = 587;   
        $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
            )
        );                                 

        $mail->setFrom('proxyemu19@gmail.com');
        $mail->addAddress('cugurel7@gmail.com');     
        $mail->isHTML(true);                                 
        $mail->Subject = 'Ziyaretçi Form Mesajı';
        $mail->Body    ="Ziyaretçi ismi: ". $name."<br>Ziyaretçi mail adresi ".$email."<br> Ziyaretçi e-posta: ".$message;
        $mail->AltBody = strip_tags($message);

        $mail->send();

        echo 'Message has been sent';
        } catch (Exception $e) 
        {
            echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
        }
        }else{
            echo "Doğrulama kodu yanlıştır";
        }


    }

Can you please help me how can i do this. My contact page yerel/yansayfa/contact. And i want to display this after submission.

Thanks!!!

cugurel
  • 27
  • 1
  • 9
  • use `redirect('controller_name/contact_method');` after `$mail->send();` – Pradeep Jul 12 '18 at 09:27
  • it says: Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/esnaf/domains/pratikesnaf.com/public_html/application/third_party/phpmailer/class.smtp.php:244) – cugurel Jul 12 '18 at 10:59
  • see this : https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Pradeep Jul 12 '18 at 11:02
  • It is okey, thank u :) – cugurel Jul 12 '18 at 12:17

1 Answers1

1

you can use redirect() or make a function on your controller and call them after finishing your progress

for example:

public function validate(){
    if($mail->send()){
        $this->next_function();
    }else{
        echo 'ops';
    }
}

public function next_function(){
    $this->load->view('name');
}
Shahmarasy
  • 114
  • 4