This repository has been archived on 2023-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
anonmail/contact-form-process.php

70 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2023-03-28 12:18:30 +02:00
<?php
if (isset($_POST['Message'])) {
2023-03-28 13:02:20 +02:00
$email_to = "recipient@example.de";
2023-03-28 12:37:38 +02:00
$email_subject = "Contact form";
2023-03-28 12:18:30 +02:00
function problem($error)
{
2023-03-28 12:37:38 +02:00
echo "There is a problem with your input:<br><br> ";
2023-03-28 12:18:30 +02:00
echo $error . "<br><br>";
echo "<br><br>";
die();
}
if (
!isset($_POST['Name']) ||
!isset($_POST['Message'])
) {
2023-03-28 12:37:38 +02:00
problem('There is a problem with your input:');
2023-03-28 12:18:30 +02:00
}
$name = $_POST['Name'];
2023-03-28 13:02:20 +02:00
$email = 'sender@example.de';
2023-03-28 12:18:30 +02:00
$message = $_POST['Message'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp, $email)) {
$error_message .= 'na .<br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
2023-03-28 12:37:38 +02:00
$error_message .= 'The registered concern does not seem to be valid!<br>';
2023-03-28 12:18:30 +02:00
}
if (strlen($message) < 2) {
2023-03-28 12:37:38 +02:00
$error_message .= 'The registered message does not seem to be valid!<br>';
2023-03-28 12:18:30 +02:00
}
if (strlen($error_message) > 0) {
problem($error_message);
}
// Formular
function clean_string($string)
{
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
2023-03-28 12:37:38 +02:00
$email_message .= "Concerns: " . clean_string($name) . "\n";
$email_message .= "Message: " . clean_string($message) . "\n";
2023-03-28 12:18:30 +02:00
// email header
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
2023-03-28 12:37:38 +02:00
Your message has been sent!
2023-03-28 12:18:30 +02:00
<?php
}
?>