Revert to PHP mail() for portability, remove AgentMail API dependency
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 24s
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 24s
This commit is contained in:
42
index.php
42
index.php
@@ -17,39 +17,7 @@ function containsHeaderInjection(string $value): bool
|
||||
return (bool) preg_match('/[\r\n]/', $value);
|
||||
}
|
||||
|
||||
// --- Send email via AgentMail API ---
|
||||
function sendContactEmail(string $subject, string $body, string $replyToEmail, string $replyToName): bool
|
||||
{
|
||||
$apiKey = getenv('AGENTMAIL_API_KEY') ?: '';
|
||||
if ($apiKey === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$apiUrl = 'https://api.agentmail.to/v0/inboxes/max-kies-media-ai-assistent@agentmail.to/messages/send';
|
||||
$payload = json_encode([
|
||||
'to' => ['mki@kies-media.de'],
|
||||
'subject' => $subject,
|
||||
'text' => $body,
|
||||
'reply_to' => $replyToEmail,
|
||||
]);
|
||||
|
||||
$ch = curl_init($apiUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer ' . $apiKey,
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return $httpCode >= 200 && $httpCode < 300;
|
||||
}
|
||||
|
||||
// --- Form processing ---
|
||||
$formErrors = [];
|
||||
@@ -103,8 +71,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$formErrors[] = 'Bitte warten Sie einen Moment vor der nächsten Anfrage.';
|
||||
}
|
||||
|
||||
// Send email via AgentMail API if no errors
|
||||
// Send email if no errors
|
||||
if (empty($formErrors)) {
|
||||
$to = 'mki@kies-media.de';
|
||||
$subject = 'Kontaktanfrage: ' . $formData['interest'];
|
||||
$body = "Von: {$formData['fname']} {$formData['lname']}\n"
|
||||
. "E-Mail: {$formData['email']}\n";
|
||||
@@ -114,7 +83,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$body .= "Anliegen: {$formData['interest']}\n\n"
|
||||
. $formData['message'];
|
||||
|
||||
$mailSent = sendContactEmail($subject, $body, $formData['email'], $formData['fname'] . ' ' . $formData['lname']);
|
||||
$headers = "From: {$formData['email']}\r\n";
|
||||
$headers .= "Reply-To: {$formData['email']}\r\n";
|
||||
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
|
||||
$headers .= "X-Mailer: PHP/" . phpversion();
|
||||
|
||||
$mailSent = mail($to, $subject, $body, $headers);
|
||||
|
||||
if ($mailSent) {
|
||||
$formSuccess = true;
|
||||
|
||||
Reference in New Issue
Block a user