feat(contact-handler.php): manager other e-mails from POST

This commit is contained in:
Jérémy Dufraisse 2024-03-18 10:35:43 +01:00
parent 1dd30c2f75
commit 0b6c22c7a3

View File

@ -7,6 +7,21 @@ $mail = new PHPMailer(true);
$errors = ''; $errors = '';
$myEmail = getenv('ASTRO_SMTP_FROM'); $myEmail = getenv('ASTRO_SMTP_FROM');
$myEmailSplitted = explode('@', $myEmail);
$domainFromMyEmail = (
empty($myEmailSplitted[1])
|| count($myEmailSplitted) != 2
) ? ''
: $myEmailSplitted[1];
$wantedContact = filter_input(INPUT_POST, 'contactTo', FILTER_VALIDATE_EMAIL);
if (
empty($wantedContact)
|| empty($domainFromMyEmail)
|| substr($wantedContact, -strlen($domainFromMyEmail)) != $domainFromMyEmail
) {
$wantedContact = $myEmail;
}
if(empty($_POST['namezzz']) || empty($_POST['emailzzz']) || empty($_POST['message'])) { if(empty($_POST['namezzz']) || empty($_POST['emailzzz']) || empty($_POST['message'])) {
$errors .= "\n Error: all fields are required"; $errors .= "\n Error: all fields are required";
@ -27,7 +42,6 @@ if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
} }
if(empty($errors)) { if(empty($errors)) {
$to = $myEmail;
$emailSubject = "[Formulaire Astrolabe] Nouveau message"; $emailSubject = "[Formulaire Astrolabe] Nouveau message";
switch ($select) { switch ($select) {
@ -66,7 +80,7 @@ if(empty($errors)) {
//Recipients //Recipients
$mail->setFrom($myEmail); $mail->setFrom($myEmail);
$mail->addAddress($myEmail); $mail->addAddress($wantedContact);
$mail->addReplyTo($emailAddress, $name); $mail->addReplyTo($emailAddress, $name);
// Content // Content