Added contact page (mailing functionnal)

This commit is contained in:
Samuel Ortion 2021-06-11 10:01:57 +02:00
parent 0e82d768d5
commit 80c373d4ce
4 changed files with 210 additions and 4 deletions

View File

View File

@ -0,0 +1,27 @@
dodeldirer
gazouiller
glouglotter
glousser
jacasser
jaser
pépier
piailler
pirouitter
pituiter
roucouler
siffler
tire-lirer
zinzibuler
zinzinuler
chanter
cancaner
nasiller
coqueliner
coqueriquer
caquetter
cocailler
coclorer
codequer
coucasser
creteller

View File

@ -1,5 +1,20 @@
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$root = realpath($_SERVER['DOCUMENT_ROOT']);
try {
$f = fopen("how_do_u_say.txt", "r");
$content = fread($f, filesize("how_do_u_say.txt"));
$verbs = preg_split("/\n/", $content);
do {
$say = $verbs[array_rand($verbs, 1)];
} while ($say == "");
} catch (Exception $e) {
echo $e->getMessage();
$say = "caqueter";
}
?>
<!DOCTYPE html>
<html lang="fr">
@ -12,10 +27,52 @@ $root = $_SERVER['DOCUMENT_ROOT'];
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
<div class="container">
<?php include("$root/menu.php");?>
<?php include("$root/header.php");?>
</div>
<section>
<div class="container flip reduced"></div>
<div class="container contact">
<h2>Babillons ensemble !</h2>
<?php
if (isset($_SESSION['msg']) && $_SESSION['msg'] != "")
{
?>
<div class="msg">
<?=$_SESSION['msg']?>
</div>
<?php
$_SESSION['msg'] = "";
}
?>
<form action="send.php" method="POST">
<label for="name">Nom*</label>
<input type="text" name="name" id="name" placeholder="Mister Cot" required>
<label for="email">Email*</label>
<input type="email" name="email" id="email" placeholder="cot.cot.cot@cocottes-minutes.fr" required>
<label for="website">Site Web</label>
<input type="url" name="website" id="website" placeholder="https://cocottes-minutes.fr">
<label for="subject">Sujet*</label>
<input type="text" name="subject" id="subject" placeholder="Cot cot ?" required>
<label for="message">Votre babillage*</label>
<textarea name="message" id="message" cols="30" rows="10" placeholder="Cot cot cot..." required></textarea>
<input type="submit" name="submit" value="<?=$say?>">
</form>
<p>* obligatoire</p>
<?php
if (isset($_SESSION['error_msg']) && $_SESSION['error_msg'] != "")
{
?>
<div class="error">
<?=$_SESSION['error_msg']?>
</div>
<?php
$_SESSION['error_msg'] = "";
}
?>
</div>
<div class="container flip reduced"></div>
</section>
<?php include("$root/footer.php");?>
<script src="/scripts/script.js"></script>

122
public/contact/send.php Normal file
View File

@ -0,0 +1,122 @@
<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$root = realpath($_SERVER['DOCUMENT_ROOT']);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require "$root/vendor/autoload.php";
function send($name, $email, $website, $subject, $message)
{
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$root = realpath($_SERVER['DOCUMENT_ROOT']);
require("config.php");
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = $smtp_host; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = $smtp_username; //SMTP username
$mail->Password = $smtp_password; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom($smtp_from, 'Mailer');
foreach ($smtp_addresses as $address)
{
$mail->addAddress($address['email'], $address['user']); //Add a recipient
}
$mail->addReplyTo($email, $name);
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64'; //Set email format to HTML
$mail->Subject = $subject;
$content = "";
$content .= "Message en provenance de la page contact des cocottes:<br>";
$content .= "De: ".$name.' <a href="mailto:'.$email.'">'.$email."</a><br>";
if ($website != "")
{
$content .= 'Site web: <a href="' . $website . '">' . $website ."</a><br>";
}
$content .= "<br>";
$content .= $message;
$mail->Body = $content;
$mail->AltBody = $message;
$mail->send();
$_SESSION['msg'] .= "Votre gazouilli a bien été envoyé \\o/.\n";
} catch (Exception $e) {
$_SESSION['error_msg'] .= "Votre gazouilli n'a malheureusement pas pu être envoyé. \n Mailer Error: {$mail->ErrorInfo}";
}
}
$_SESSION['error_msg'] = "";
$_SESSION['msg'] = "";
if (isset($_POST['submit']))
{
if (isset($_POST['name']) and $_POST['name'] != "")
{
$name = $_POST['name'];
} else
{
$_SESSION['error_msg'] .= "Mais quel est votre nom, chère cocotte ?\n";
}
if (isset($_POST['email']) and $_POST['email'] != "")
{
$email = $_POST['email'];
} else
{
$_SESSION['error_msg'] .= "Et votre email ?\n";
}
if (isset($_POST['website']) and $_POST['website'] != "")
{
$website = $_POST['website'];
} else {
$website = "";
}
if (isset($_POST['subject']) and $_POST['subject'] != "")
{
$subject = $_POST['subject'];
} else
{
$_SESSION['error_msg'] .= "De quoi voulez vous nous parler ?";
}
if (isset($_POST['message']) and $_POST['message'] != "")
{
$message = $_POST['message'];
} else
{
$_SESSION['error_msg'] .= "Vous caqueter bien faiblement ma pauvre cocotte, vous n'aviez rien à nous dire ?\n";
}
} else
{
$_SESSION['error_msg'] .= "Vous n'avez pas soumis le formulaire de contact.\n";
}
if ($_SESSION['error_msg'] == "")
{
send($name, $email, $website, $subject, $message);
}
// echo $_SESSION['error_msg'];
// echo $_SESSION['msg'];
header('Location: /contact');
?>