2020-06-23 13:44:10 +02:00
|
|
|
|
<?php
|
2023-01-04 18:04:37 +01:00
|
|
|
|
require("/usr/share/php/libphp-phpmailer/autoload.php");
|
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
|
|
|
|
|
|
$mail = new PHPMailer(true);
|
|
|
|
|
|
2020-06-23 13:44:10 +02:00
|
|
|
|
$errors = '';
|
2023-01-04 18:04:37 +01:00
|
|
|
|
$myEmail = getenv('ASTRO_SMTP_FROM');
|
2020-06-23 13:44:10 +02:00
|
|
|
|
|
2020-08-17 16:29:26 +02:00
|
|
|
|
if(empty($_POST['namezzz']) || empty($_POST['emailzzz']) || empty($_POST['message'])) {
|
2020-06-23 13:44:10 +02:00
|
|
|
|
$errors .= "\n Error: all fields are required";
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-17 16:29:26 +02:00
|
|
|
|
if(!empty($_POST['name']) && !empty($_POST['email'])) {
|
|
|
|
|
$errors .= "\n Error: spam";
|
2023-01-04 18:04:37 +01:00
|
|
|
|
}
|
2020-08-17 16:29:26 +02:00
|
|
|
|
|
|
|
|
|
$name = $_POST['namezzz'];
|
|
|
|
|
$emailAddress = $_POST['emailzzz'];
|
2020-06-23 13:44:10 +02:00
|
|
|
|
$select = $_POST['select'];
|
|
|
|
|
$message = $_POST['message'];
|
2020-07-08 17:07:15 +02:00
|
|
|
|
$subscribe = $_POST['subscribe'];
|
2020-06-23 13:44:10 +02:00
|
|
|
|
|
|
|
|
|
if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
|
$errors .= "\n Error: Invalid email address $emailAddress";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( empty($errors)) {
|
|
|
|
|
$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";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$emailBody = "Vous avez reçu un nouveau message depuis le formulaire du site Astrolabe :".
|
2023-01-04 18:04:37 +01:00
|
|
|
|
"\r\n\r\nNom: $name \r\nEmail: $emailAddress \r\nRaison: $purpose\r\nSubscribe: $subscribe\r\n\r\n$message";
|
2020-06-23 13:44:10 +02:00
|
|
|
|
|
|
|
|
|
$emailBodyHTML = str_replace("\r\n", "<br>", $emailBody);
|
|
|
|
|
|
2023-01-04 18:04:37 +01:00
|
|
|
|
$mail->isSMTP();
|
|
|
|
|
$mail->Host = getenv('ASTRO_SMTP_HOSTNAME');
|
|
|
|
|
$mail->SMTPAuth = true;
|
|
|
|
|
$mail->Username = getenv('ASTRO_SMTP_USERNAME');
|
|
|
|
|
$mail->Password = getenv('ASTRO_SMTP_PASSWORD');
|
|
|
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
|
|
|
|
$mail->Port = 587;
|
|
|
|
|
|
|
|
|
|
//Options
|
|
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
|
$mail->WordWrap = 70;
|
|
|
|
|
|
|
|
|
|
//Recipients
|
|
|
|
|
$mail->setFrom($myEmail);
|
|
|
|
|
//$mail->addAddress($myEmail);
|
|
|
|
|
$mail->addAddress('anthony@6clones.fr');
|
|
|
|
|
$mail->addReplyTo($emailAddress, $name);
|
|
|
|
|
|
|
|
|
|
// Content
|
|
|
|
|
$mail->isHTML(true);
|
|
|
|
|
$mail->Subject = $emailSubject;
|
|
|
|
|
$mail->Body = $emailBodyHTML;
|
|
|
|
|
$mail->AltBody = $emailBody;
|
|
|
|
|
|
|
|
|
|
$mail->send();
|
2020-07-08 17:07:15 +02:00
|
|
|
|
|
|
|
|
|
// if subscribe add to mailing list
|
|
|
|
|
if(!empty($subscribe)) {
|
|
|
|
|
// process
|
2020-07-14 19:07:00 +02:00
|
|
|
|
// enovoi mail add to mailing list
|
2020-07-08 17:07:15 +02:00
|
|
|
|
}
|
2020-06-23 13:44:10 +02:00
|
|
|
|
|
|
|
|
|
// redirect to the 'thank you' page
|
2020-06-26 16:23:50 +02:00
|
|
|
|
header("Location: /thank-you/index.html");
|
2020-06-23 13:44:10 +02:00
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
<!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>
|