refactor(contact-handler.php): PSR2 autoformat
This commit is contained in:
parent
b58b2357c0
commit
1dd30c2f75
@ -1,102 +1,102 @@
|
|||||||
<?php
|
<?php
|
||||||
require("/usr/share/php/libphp-phpmailer/autoload.php");
|
require("/usr/share/php/libphp-phpmailer/autoload.php");
|
||||||
use PHPMailer\PHPMailer\PHPMailer;
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
use PHPMailer\PHPMailer\Exception;
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
$mail = new PHPMailer(true);
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
$errors = '';
|
$errors = '';
|
||||||
$myEmail = getenv('ASTRO_SMTP_FROM');
|
$myEmail = getenv('ASTRO_SMTP_FROM');
|
||||||
|
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_POST['name']) && !empty($_POST['email'])) {
|
if(!empty($_POST['name']) && !empty($_POST['email'])) {
|
||||||
$errors .= "\n Error: spam";
|
$errors .= "\n Error: spam";
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $_POST['namezzz'];
|
$name = $_POST['namezzz'];
|
||||||
$emailAddress = $_POST['emailzzz'];
|
$emailAddress = $_POST['emailzzz'];
|
||||||
$select = $_POST['select'];
|
$select = $_POST['select'];
|
||||||
$message = $_POST['message'];
|
$message = $_POST['message'];
|
||||||
$subscribe = $_POST['subscribe'];
|
$subscribe = $_POST['subscribe'];
|
||||||
|
|
||||||
if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
||||||
$errors .= "\n Error: Invalid email address $emailAddress";
|
$errors .= "\n Error: Invalid email address $emailAddress";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( empty($errors)) {
|
if(empty($errors)) {
|
||||||
$to = $myEmail;
|
$to = $myEmail;
|
||||||
$emailSubject = "[Formulaire Astrolabe] Nouveau message";
|
$emailSubject = "[Formulaire Astrolabe] Nouveau message";
|
||||||
|
|
||||||
switch ($select) {
|
switch ($select) {
|
||||||
case "option 1":
|
case "option 1":
|
||||||
$purpose = "Demande de rendez-vous";
|
$purpose = "Demande de rendez-vous";
|
||||||
break;
|
break;
|
||||||
case "option 2":
|
case "option 2":
|
||||||
$purpose = "Demande de précisions sur le statut d’entrepreneur salarié";
|
$purpose = "Demande de précisions sur le statut d’entrepreneur salarié";
|
||||||
break;
|
break;
|
||||||
case "option 3":
|
case "option 3":
|
||||||
$purpose = "Proposition de misson";
|
$purpose = "Proposition de misson";
|
||||||
break;
|
break;
|
||||||
case "option 4":
|
case "option 4":
|
||||||
$purpose = "Proposition de partenariat";
|
$purpose = "Proposition de partenariat";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$purpose = "Autre demande";
|
$purpose = "Autre demande";
|
||||||
}
|
}
|
||||||
|
|
||||||
$emailBody = "Vous avez reçu un nouveau message depuis le formulaire du site Astrolabe :".
|
$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\nSubscribe: $subscribe\r\n\r\n$message";
|
"\r\n\r\nNom: $name \r\nEmail: $emailAddress \r\nRaison: $purpose\r\nSubscribe: $subscribe\r\n\r\n$message";
|
||||||
|
|
||||||
$emailBodyHTML = str_replace("\r\n", "<br>", $emailBody);
|
$emailBodyHTML = str_replace("\r\n", "<br>", $emailBody);
|
||||||
|
|
||||||
$mail->isSMTP();
|
$mail->isSMTP();
|
||||||
$mail->Host = getenv('ASTRO_SMTP_HOSTNAME');
|
$mail->Host = getenv('ASTRO_SMTP_HOSTNAME');
|
||||||
$mail->SMTPAuth = true;
|
$mail->SMTPAuth = true;
|
||||||
$mail->Username = getenv('ASTRO_SMTP_USERNAME');
|
$mail->Username = getenv('ASTRO_SMTP_USERNAME');
|
||||||
$mail->Password = getenv('ASTRO_SMTP_PASSWORD');
|
$mail->Password = getenv('ASTRO_SMTP_PASSWORD');
|
||||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||||
$mail->Port = 587;
|
$mail->Port = 587;
|
||||||
|
|
||||||
//Options
|
//Options
|
||||||
$mail->CharSet = 'UTF-8';
|
$mail->CharSet = 'UTF-8';
|
||||||
$mail->WordWrap = 70;
|
$mail->WordWrap = 70;
|
||||||
|
|
||||||
//Recipients
|
//Recipients
|
||||||
$mail->setFrom($myEmail);
|
$mail->setFrom($myEmail);
|
||||||
$mail->addAddress($myEmail);
|
$mail->addAddress($myEmail);
|
||||||
$mail->addReplyTo($emailAddress, $name);
|
$mail->addReplyTo($emailAddress, $name);
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
$mail->isHTML(true);
|
$mail->isHTML(true);
|
||||||
$mail->Subject = $emailSubject;
|
$mail->Subject = $emailSubject;
|
||||||
$mail->Body = $emailBodyHTML;
|
$mail->Body = $emailBodyHTML;
|
||||||
$mail->AltBody = $emailBody;
|
$mail->AltBody = $emailBody;
|
||||||
|
|
||||||
$mail->send();
|
$mail->send();
|
||||||
|
|
||||||
// if subscribe add to mailing list
|
// if subscribe add to mailing list
|
||||||
if(!empty($subscribe)) {
|
if(!empty($subscribe)) {
|
||||||
// process
|
// process
|
||||||
// enovoi mail add to mailing list
|
// enovoi mail add to mailing list
|
||||||
}
|
}
|
||||||
|
|
||||||
// redirect to the 'thank you' page
|
// redirect to the 'thank you' page
|
||||||
header("Location: /thank-you/index.html");
|
header("Location: /thank-you/index.html");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Contact form handler</title>
|
<title>Contact form handler</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- This page is displayed only if there is some error -->
|
<!-- This page is displayed only if there is some error -->
|
||||||
<?php
|
<?php
|
||||||
echo nl2br($errors);
|
echo nl2br($errors);
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user