61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<link rel="stylesheet" href="/css/contact.css">
|
|
<h1>Kontaktujte mě</h1>
|
|
|
|
<form class="form_contact" action="/contact/send" method="post" name="contact">
|
|
<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>
|
|
</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
|
|
if(isset($_POST['email']) && isset($_POST['message'])) {
|
|
$email = $_POST['email'];
|
|
$message = $_POST['message'];
|
|
$name = $_POST['name'];
|
|
|
|
require_once(__DIR__ . "/../../libraries/mail.php");
|
|
$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()) {
|
|
console_log("zprava odeslana");
|
|
console_log("zprava:");
|
|
console_log($m);
|
|
header('Location: /?sent=true');
|
|
} else {
|
|
console_log("zprava neodeslana");
|
|
console_log($m);
|
|
echo "<p>Něco se nepovedlo, zkuste to znovu... :(</p>";
|
|
echo "<a href='/'>Zpět</a>";
|
|
}
|
|
}
|