PHP mail kommt nur lokal an?
Hallo, ich habe das problem, dass meine PHP mail nur lokal ankommtl, jedoch nicht wenn ich sie an einen externen Mailprovider schicke, dass ist mein code
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Statusmeldung</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #191919;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
text-align: center;
padding: 20px;
background-color: #2a2a2a;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
margin-bottom: 20px;
}
.success {
color: green;
}
.error {
color: red;
}
.back-button {
margin-top: 20px;
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.back-button:hover {
background-color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Statusmeldung</h1>
<button class="back-button" onclick="window.history.back()">Zurück</button>
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Spam-Schutz: Überprüfen, ob genügend Zeit seit dem letzten Absenden vergangen ist (1 Stunde)
if (isset($_SESSION['last_submit_time']) && time() - $_SESSION['last_submit_time'] < 600) {
$timeLeft = 600 - (time() - $_SESSION['last_submit_time']);
echo "<p class='error'>Bitte warten Sie noch $timeLeft Sekunden, bevor Sie das Formular erneut absenden. Die Ankunft der Email kann bis zu 24h dauern.</p>";
exit;
}
// Aktualisieren der letzten Absendezeit
$_SESSION['last_submit_time'] = time();
// Weiter mit der E-Mail-Versendung
$to = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$subject = 'Backup Bier aus dem Schlauch';
$message = 'Hey, hier ist dein Backup von Bier aus dem Schlauch.';
$headers = "From: noreply@bierausdemschlauch.de";
$data = $_POST['exportedFile'];
$fileName = $_POST['fileName'];
$fileContent = base64_decode($data);
$separator = md5(time());
$eol = PHP_EOL;
// Main headers
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
// Message
$body = "--" . $separator . $eol;
$body .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
$body .= $message . $eol;
// Attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $fileName . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment; filename=\"" . $fileName . "\"" . $eol . $eol;
$body .= chunk_split(base64_encode($fileContent)) . $eol;
$body .= "--" . $separator . "--";
if (mail($to, $subject, $body, $headers)) {
// Benachrichtigung über Erfolg
echo "<p class='success'>E-Mail erfolgreich gesendet.</p>";
} else {
// Benachrichtigung über Misserfolg
echo "<p class='error'>E-Mail konnte nicht gesendet werden.</p>";
}
} else {
echo "<p class='error'>Ungültige Anforderung.</p>";
}
?>
</div>
</body>
</html>