Lisää yhteydenottolomakkeen PHP-backend ja vaihda sähköposti
- send.php: lomake lähettää sähköpostin box@storagebox.fi:hin - script.js: lomake POSTaa send.php:lle async/await:lla - Vaihdettu info@storagebox.fi -> box@storagebox.fi - Validointi, header injection -suojaus, UTF-8 tuki Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
70
send.php
Normal file
70
send.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// Vain POST sallittu
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'message' => 'Method not allowed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Lomakkeen tiedot
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$package = trim($_POST['package'] ?? '');
|
||||
$message = trim($_POST['message'] ?? '');
|
||||
|
||||
// Validointi
|
||||
if (empty($name) || empty($email) || empty($message)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Täytä kaikki pakolliset kentät.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Virheellinen sähköpostiosoite.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Suojaa header injectionilta
|
||||
$name = str_replace(["\r", "\n"], '', $name);
|
||||
$email = str_replace(["\r", "\n"], '', $email);
|
||||
|
||||
// Sähköpostin vastaanottaja
|
||||
$to = 'box@storagebox.fi';
|
||||
|
||||
// Aihe
|
||||
$subject = 'StorageBox.fi - Yhteydenotto: ' . $name;
|
||||
|
||||
// Viestin sisältö
|
||||
$body = "Uusi yhteydenotto StorageBox.fi:n kautta\n";
|
||||
$body .= "========================================\n\n";
|
||||
$body .= "Nimi: {$name}\n";
|
||||
$body .= "Sähköposti: {$email}\n";
|
||||
if (!empty($package)) {
|
||||
$packages = [
|
||||
'mini' => 'Mini — 100 GB — 29€/v',
|
||||
'perus' => 'Perus — 200 GB — 69€/v',
|
||||
'plus' => 'Plus — 500 GB — 119€/v',
|
||||
'pro' => 'Pro — 1 TB — 199€/v',
|
||||
'business' => 'Business — 2 TB — 299€/v',
|
||||
];
|
||||
$packageName = $packages[$package] ?? $package;
|
||||
$body .= "Paketti: {$packageName}\n";
|
||||
}
|
||||
$body .= "\nViesti:\n{$message}\n";
|
||||
|
||||
// Headerit
|
||||
$headers = "From: StorageBox.fi <box@storagebox.fi>\r\n";
|
||||
$headers .= "Reply-To: {$name} <{$email}>\r\n";
|
||||
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
|
||||
$headers .= "X-Mailer: StorageBox.fi Contact Form\r\n";
|
||||
|
||||
// Lähetä
|
||||
if (mail($to, '=?UTF-8?B?' . base64_encode($subject) . '?=', $body, $headers)) {
|
||||
echo json_encode(['success' => true, 'message' => 'Viesti lähetetty! Palaamme asiaan pian.']);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Viestin lähetys epäonnistui. Ota yhteyttä suoraan: box@storagebox.fi']);
|
||||
}
|
||||
Reference in New Issue
Block a user