F
F
FIKSER2018-03-12 21:20:57
PHP
FIKSER, 2018-03-12 21:20:57

How to make a redirect in php form handler?

<?php 
 
$sendto   = "[email protected]"; // Куда отправлять
$yarcc = $_POST['year'];
$namecc = $_POST['name'];
$mail = $_POST['email'];


// Тема сообщения
$subject  = "test!!";
$headers  = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8 \r\n";
 
// Структура сообщения
$msg  = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Новый заказ!</h2>\r\n";
$msg .= "<p><strong>ИМЯ:</strong> ".$namecc."</p>\r\n";
$msg .= "<p><strong>type:</strong> ".$type."</p>\r\n";
$msg .= "<p><strong>maill :</strong> ".$mail."</p>\r\n";
$msg .= "</body></html>";
 
// Результат отправки


if(@mail($sendto, $subject, $msg, $headers)) {
    echo "<center><img src='images/spasibo.png'></center>";
} else {
    echo "<center><img src='images/ne-tpravleno.png'></center>";
}
 
?>

How to make a redirect to the main page of the site? With ajax, the handler did not work, I decided to simply redirect to the main page through php.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-03-12
@FIKSER

Good evening.
Something like that

if(@mail($sendto, $subject, $msg, $headers)) {
    header("Location: index.php");
} else {
    echo "<center><img src='images/ne-tpravleno.png'></center>";
}

More details here .
And don't use "@" in your code unless absolutely necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question