Cześć, mam taki o to skrypt wysyłający maila. Potrzebuję zrobić tak, aby error wyświetlany był na stronie głównej, a nie w pliku, w którym wykonywany jest skrypt. Ktoś ma jakiś pomysł?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg_content = $_POST['msg_content'];
//Require field names
$required = array('name', 'email', 'phone', 'msg_content');
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
$error_message = '<div class="dark-bg">
<div class="error">
<div class="thead flex justify-content align-items">
<p>Ups..</p>
<div class="icon">
<div class="x-times"></div>
</div>
</div>
<p class="content">Wysyłanie maila nie powiodło się!<br>Wypełnij wszystkie pola i spróbuj ponownie.</p>
</div>
</div>';
header('Location: index.php');
} else {
$to = "kontakt@test.pl";
$subject = "Wiadomość ze strony TEST";
$message = '
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>UWAGA! Ta wiadomość została przesłana ze strony <b>TEST</b></p>
<table>
<tr>
<td><b>Imię i nazwisko:</b> '.$name.'</td>
</tr>
<tr>
<td><b>Telefon kontaktowy:</b> '.$phone.'</td>
</tr>
<tr>
<td><b>Adres e-mail:</b> '.$email.'</td>
</tr>
<tr>
<td><b>Treść wiadomości:</b> '.$msg_content.'</td>
</tr>
</tr>
</table>
</body>
</html>
';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: '.$email.'' . "\r\n";
mail($to,$subject,$message,$headers);
header('Location: index.php');
}
?>