diff --git a/backend/config.php b/backend/config.php new file mode 100644 index 0000000..05369cf --- /dev/null +++ b/backend/config.php @@ -0,0 +1,7 @@ + 'dev@andre-kempf.com', + 'from_email' => 'noreply@andre-kempf.com', + 'app_name' => 'Portfolio Contact', +]; \ No newline at end of file diff --git a/backend/sendMail.php b/backend/sendMail.php new file mode 100644 index 0000000..d18a452 --- /dev/null +++ b/backend/sendMail.php @@ -0,0 +1,67 @@ +website)) { + http_response_code(200); + echo json_encode(["status" => "success"]); + exit; + } + + // 2. Sanitize inputs & set fallbacks + $email = filter_var($params->email ?? '', FILTER_VALIDATE_EMAIL); + $name = htmlspecialchars(trim($params->name ?? 'Anonymous'), ENT_QUOTES, 'UTF-8'); + $text = htmlspecialchars(trim($params->message ?? ''), ENT_QUOTES, 'UTF-8'); + + // Validate required fields + if (!$email || empty($text)) { + http_response_code(400); + echo json_encode(["status" => "error", "message" => "Invalid input"]); + exit; + } + + // 3. Render template + $emailBody = renderEmailTemplate($name, $email, $text, $params->message ?? ''); + $subject = "{$config['app_name']}: $name"; + + // 4. Set headers + $headers = [ + 'MIME-Version: 1.0', + 'Content-type: text/html; charset=utf-8', + "From: {$config['from_email']}", + "Reply-To: $email" + ]; + + // Send email + $success = mail($config['recipient_email'], $subject, $emailBody, implode("\n", $headers)); + + if ($success) { + http_response_code(200); + echo json_encode(["status" => "success"]); + } else { + http_response_code(500); + echo json_encode(["status" => "error"]); + } + break; + + default: // Reject any other HTTP method + header("Allow: POST", true, 405); + exit; +} \ No newline at end of file diff --git a/backend/templates/emailTemplate.php b/backend/templates/emailTemplate.php new file mode 100644 index 0000000..7f31a0c --- /dev/null +++ b/backend/templates/emailTemplate.php @@ -0,0 +1,35 @@ + +