isSMTP(); //Send using SMTP $mail->Host = $smtp_host; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = $smtp_user; //SMTP username $mail->Password = $smtp_password; //SMTP password if ($smtp_secure) { $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption } $mail->Port = $smtp_port; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom($smtp_from, 'Chill website'); $mail->addAddress($smtp_to); $mail->addReplyTo($_POST['email']); //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = 'Message de chill.social : ' . $_POST['subject']; $body = ''; foreach (['subject' => "Sujet", 'email' => 'E-mail', 'message' => 'Message'] as $k => $v) { $body .= '
' . $v . '
' . nl2br($_POST[$k]) . '
Extra info :
' . var_export([
"REMOTE_ADDR" => $_SERVER["REMOTE_ADDR"],
"HTTP_X_FORWARDED_FOR" => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : "not set",
"HTTP_CLIENT_IP" => isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : "not set",
"HTTP_USER_AGENT" => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "not set"
], $return = true) . '';
$mail->Body = $body;
$mail->send();
echo "Merci pour votre message.";
exit();
} catch (Exception $e) {
http_response_code(500);
echo "Une erreur est survenue lors de l'envoie de votre message, veuillez ré-essayer. Si le problème persiste contactez-nous directement à info@champs-libres.coop";
if ($debug ?? false) {
echo "\nException : ". $e->getMessage();
}
exit();
}
} else {
http_response_code(400);
echo "Le message n'a pas pu être envoyé, veuillez ré-essayer (raison: Origine inconnue ou non autorisée).";
exit();
}
$mail = new PHPMailer(true);