L
L
L1nw0od2016-09-24 14:40:44
PHP
L1nw0od, 2016-09-24 14:40:44

Redirect (php) after submitting form to mail?

Good day, please tell me how to make a redirect!
the code all works, after submitting the form, I display a message that everything was sent successfully, and after 5 seconds you need to redirect to another page!
Here is my php code

<?
 header("Content-Type: text/html; charset=utf-8");
function complete_mail() {
 
 
        $empty_input[] = 'Имя';
        $empty_input[] = 'Номер телефона';
        for ($i=0; $i<count($_POST['input_name']); $i++) {
              $_POST['input_name'][$i] = substr(htmlspecalchars(trim($_POST['input_name'][$i])), 0, 100000);
              if(substr(htmlspecialchars(trim($_POST['check'][$i])), 0, 1) == 1) {
                 if(empty($_POST['input_name'][$i])) {
                         $sendemail = 'No';
                         echo '<br /><b>Необходимо заполнить поле '.$empty_input[$i].'!</b>';
 
                 }
              }
        }
        if($sendemail == No) show_form();
        $mess = '';
    
$mess .= '<b>Имя: </b>'.$_POST['input_name'][0].'<br />';
$mess .= '<b>Номер телефона: </b>'.$_POST['input_name'][1].'<br />';
// подключаем файл класса для отправки почты
// если Вы забыли его скачать - http://www.php-mail.ru/class.phpmailer.zip
        require 'class.phpmailer.php';
header("Content-Type: text/html; charset=utf-8");
        $mail = new PHPMailer();
    $charset = "UTF-8";
        $mail->From = 'client.mail';      // от кого email
        $mail->FromName = 'Клиент';   // от кого имя
        $mail->IsHTML(true);        // выставляем формат письма HTML
        $mail->Subject = 'Zagolovok';  // тема письма
        $mail->Body = $mess;
$headers .= "Content-type: text/html; charset=\"utf-8\"";
        // если был файл, то прикрепляем его к письму
                      if(isset($_FILES['file_name'])) {
                               if($_FILES['file_name']['error'][0] == 0){
                                  $mail->AddAttachment($_FILES['file_name']['tmp_name'][0], $_FILES['file_name']['name'][0]);
                               }
                      }
                      // если был файл, то прикрепляем его к письму
                      if(isset($_FILES['file_name'])) {
                               if($_FILES['file_name']['error'][1] == 0){
                                  $mail->AddAttachment($_FILES['file_name']['tmp_name'][1], $_FILES['file_name']['name'][1]);
                               }
                      }
                      // если был файл, то прикрепляем его к письму
                      if(isset($_FILES['file_name'])) {
                               if($_FILES['file_name']['error'][2] == 0){
                                  $mail->AddAttachment($_FILES['file_name']['tmp_name'][2], $_FILES['file_name']['name'][2]);
                               }
                      }
                      
 
        if($sendemail != 'No'){
              // отправляем наше письмо
            $headers .= "Content-type: text/html; charset=\"utf-8\"";
              if (!$mail->Send()) die ('Mailer Error: '.$mail->ErrorInfo);
              echo 'Спасибо! Ваше письмо отправлено.';
        }
}
$headers .= "Content-type: text/html; charset=\"utf-8\"";
if (!empty($_POST['submit'])) complete_mail();
else show_form();
 
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-09-24
@webinar

if 5 seconds after loading the page, then you already need to do it in js:
javascript.ru/settimeout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question