74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
||
$errors = '';
|
||
$myEmail = 'contact@astrolabe.coop'; // email address to send form content
|
||
|
||
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
|
||
$errors .= "\n Error: all fields are required";
|
||
}
|
||
|
||
$name = $_POST['name'];
|
||
$emailAddress = $_POST['email'];
|
||
$select = $_POST['select'];
|
||
$message = $_POST['message'];
|
||
|
||
if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
||
$errors .= "\n Error: Invalid email address $emailAddress";
|
||
}
|
||
|
||
if( empty($errors)) {
|
||
$headers = array(
|
||
"From: " .$myEmail,
|
||
"Reply-To: " .$emailAddress,
|
||
"MIME-Version: 1.0",
|
||
"Content-Type: text/html;charset=UTF-8",
|
||
"Content-Transfer-Encoding:8bit"
|
||
);
|
||
|
||
$to = $myEmail;
|
||
$emailSubject = "[Formulaire Astrolabe] Nouveau message";
|
||
|
||
switch ($select) {
|
||
case "option 1":
|
||
$purpose = "Demande de rendez-vous";
|
||
break;
|
||
case "option 2":
|
||
$purpose = "Demande de précisions sur le statut d’entrepreneur salarié";
|
||
break;
|
||
case "option 3":
|
||
$purpose = "Proposition de misson";
|
||
break;
|
||
case "option 4":
|
||
$purpose = "Proposition de partenariat";
|
||
break;
|
||
default:
|
||
$purpose = "Autre demande";
|
||
}
|
||
|
||
$messageWrap = wordwrap($message, 70, "\r\n", false);
|
||
|
||
$emailBody = "Vous avez reçu un nouveau message depuis le formulaire du site Astrolabe :".
|
||
"\r\n\r\nNom: $name \r\nEmail: $emailAddress \r\nRaison: $purpose\r\n\r\n$messageWrap";
|
||
|
||
$emailBodyHTML = str_replace("\r\n", "<br>", $emailBody);
|
||
|
||
// send the email
|
||
mail($to, $emailSubject, $emailBodyHTML, implode("\r\n", $headers));
|
||
|
||
// redirect to the 'thank you' page
|
||
header("Location: /thank-you/index.html");
|
||
}
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<title>Contact form handler</title>
|
||
</head>
|
||
|
||
<body>
|
||
<!-- This page is displayed only if there is some error -->
|
||
<?php
|
||
echo nl2br($errors);
|
||
?>
|
||
</body>
|
||
</html>
|