website/pages/contact/contact.php

61 lines
1.8 KiB
PHP
Raw Normal View History

2023-03-05 17:45:43 +01:00
<link rel="stylesheet" href="/css/contact.css">
<h1>Kontaktujte </h1>
<form class="form_contact" action="/contact/send" method="post" name="contact">
2023-03-05 17:45:43 +01:00
<label for="name">Vaše jméno:</label>
<input id="name" type="text" placeholder="Petr Novák" required autocomplete="on" />
<label for="email">Váš e-mail:</label>
<input id="email" type="email" placeholder="petr@novak.cz" required autocomplete="on" />
<label for="message">Zpráva:</label>
<textarea id="message" placeholder="Napište zprávu..." required></textarea>
<button type="button" id="submit">Odeslat zprávu</button>
2023-03-05 17:45:43 +01:00
</form>
<script>
const submit = document.querySelector("#submit")
submit.addEventListener("click", (e) => {
e.preventDefault()
const formData = new FormData();
formData.append('name', document.querySelector("#name").value);
formData.append('email', document.querySelector("#email").value);
formData.append('message', document.querySelector("#message").value);
try {
fetch('/contact/send', {
method: 'POST',
body: formData
});
console.log('Message sent successfully.')
} catch (err) {
console.error('Error:', error)
}
})
</script>
<?php
2023-04-16 12:37:28 +02:00
ini_set('log_errors', 1);
if(isset($_POST['email']) && isset($_POST['message'])) {
$email = $_POST['email'];
$message = $_POST['message'];
$name = $_POST['name'];
require_once(__DIR__ . "/../../libraries/mail.php");
2023-04-13 17:43:51 +02:00
$message = "Nová zpráva z webu filiprojek.cz\n\nOdesílatel: $email\nZpráva:\n$message";
$m = new Mail($_POST['email'], 'webmaster@filiprojek.cz', 'Nová zpráva z webu filiprojek.cz', $message);
if($m->send()) {
2023-04-16 12:32:07 +02:00
console_log("zprava odeslana");
header('Location: /?sent=true');
} else {
2023-04-16 12:37:28 +02:00
error_log("Message wasn't sent");
error_log($m);
echo "<p>Něco se nepovedlo, zkuste to znovu... :(</p>";
echo "<a href='/'>Zpět</a>";
}
}