Switch to SMTP mail sending via mail2.fi

Replace PHP mail() with direct SMTP authentication through
mail2.fi to ensure reliable email delivery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 00:31:40 +02:00
parent 501ca783af
commit 982e6c34bd
3 changed files with 149 additions and 12 deletions

18
api.php
View File

@@ -1,5 +1,6 @@
<?php
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/smtp.php';
// Rate limiting (simple file-based)
function checkRateLimit($ip, $maxRequests = 5, $windowSeconds = 300) {
@@ -110,13 +111,9 @@ switch ($action) {
if ($phone) $body .= "Puhelin: $phone\n";
$body .= "\nViesti:\n$message\n";
$headers = "From: asiakaspalvelu@konesaliturku.fi\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$mailResult = smtp_send($to, $subject, $body, $email);
@mail($to, $subject, $body, $headers);
echo json_encode(['success' => true]);
echo json_encode(['success' => true, 'mail_sent' => $mailResult['ok']]);
break;
case 'quote':
@@ -288,16 +285,13 @@ switch ($action) {
}
file_put_contents($quoteFile, json_encode($quotes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
// Send email
// Send email via SMTP
$to = 'asiakaspalvelu@konesaliturku.fi';
$subject = 'Tarjouspyyntö: ' . $name . ($company ? " ($company)" : '');
$headers = "From: asiakaspalvelu@konesaliturku.fi\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$mailSent = mail($to, $subject, $body, $headers);
$mailResult = smtp_send($to, $subject, $body, $email);
echo json_encode(['success' => true, 'mail_sent' => $mailSent]);
echo json_encode(['success' => true, 'mail_sent' => $mailResult['ok'], 'mail_debug' => $mailResult['error'] ?? null]);
break;
default: