SAE_S1.05_S1.06/php/send_message_client.php

44 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2024-01-19 13:10:24 +01:00
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
2024-01-19 13:22:08 +01:00
use PHPMailer\PHPMailer\SMTP;
require 'PHP/fichier/php/PHP/PHPMailer/src/Exception.php';
require 'PHP/fichier/php/PHP/PHPMailer/src/PHPMailer.php';
require 'PHP/fichier/php/PHP/PHPMailer/src/SMTP.php';
2024-01-19 13:10:24 +01:00
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$mail = new PHPMailer(true);
try {
// Paramètres du serveur SMTP
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
2024-04-17 21:51:23 +02:00
$mail->Username = 'CONFIDENTIEL';
$mail->Password = 'CONFIDENTIEL';
2024-01-19 13:10:24 +01:00
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom($email, $name);
2024-04-17 21:51:23 +02:00
$mail->addAddress('CONFIDENTIEL', 'Neo Eat');
2024-01-19 13:10:24 +01:00
$mail->isHTML(false);
2024-01-19 13:22:08 +01:00
$mail->Subject = 'Nouveau message client !';
2024-01-19 13:10:24 +01:00
$mail->Body = "Name: $name\nEmail: $email\nMessage:\n$message";
$mail->send();
header("Location: ../html/messageSucces.html");
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>