Hi. I'm trying to send mail with simple script like this:
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
echo 'Invalid email address.';
exit;
}
$message = htmlspecialchars($_POST['message']);
$to = 'contact@stefanak.serv00.net';
$subject = 'New Contact Form Submission';
$headers = [
'From' => $email,
'Reply-To' => $email,
'Content-Type' => 'text/plain; charset=UTF-8',
'X-Mailer' => 'PHP/' . phpversion(),
];
$body = "Name: $name\r\nEmail: $email\r\n\r\nMessage:\r\n" . wordwrap($message, 70, "\r\n");
if (mail($to, $subject, $body, $headers)) {
http_response_code(200);
echo 'Message sent successfully.';
} else {
http_response_code(500);
echo 'Failed to send the message.';
}
But it always ends with fail (code 500). I cannot solve why. I use "to" email address which I've created in my serv00 administration. I tried to enable mail.log with .user.ini but there is also no error. Can somebody help me please? What am I doing wrong?