Greg_Lumiere a écrit :
Mais vous définissez où $melName, $melEmail, $melMsg etc ?
D'ailleurs je ne comprends pas cette construction de echo.
un simple
echo $variable;
se suffit à lui même pour le même résultat.
Je les définis dans mon script en local.
Comme en définissant dans le script que j'ai posté, le code sera trop long
Sinon voilà le tout:
<?php
/**
* Contact form my website
*
*/
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
header('Allow: POST');
header('HTTP/1.1 405 Method Not Allowed');
header('Content-Type: text/plain');
exit;
}
session_start();
/**
* [Sécurise les champs du formulaire qui ne doivent pas contenir de html]
* @param [string] $champ [champ brut envoyé par le formulaire]
* @return [string] [chaine de caractères sécurisée]
*/
function mailCleanChamps($champ) {
return htmlentities(trim(strip_tags(stripslashes($champ))), ENT_NOQUOTES, "UTF-8");
}
/**
* [Sécurise les champs de texte du formulaire susceptibles de contenir du html (textareas)]
* @param [string] $champ [champ brut envoyé par le formulaire]
* @return [string] [chaine de caractères sécurisée]
*/
function mailCleanMessage($champ) {
return strip_tags(htmlentities(trim(stripslashes($champ)), ENT_NOQUOTES, "UTF-8"));
}
$melName = "<style>.dialog{-webkit-perspective:1300px;font-family:brandon_text_regularregular;perspective:1300px;position:fixed;top:50%;left:50%;width:50%;max-width:625px;min-width:240px;height:auto;z-index:2000;visibility:visible;-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);}.navmsg__content-s,.navmsg__content-a{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-transform:rotateY(-70deg);transform:rotateY(-70deg);transition:all .3s;opacity:0;border-radius:3px}.dialog{visibility:visible;}.navmsg__content-s,.navmsg__content-a{-webkit-transform:rotateY(0);transform:rotateY(0);opacity:1}.navmsg__close-s,.navmsg__close-a{-webkit-animation:slide-modal-content .4s both;animation:slide-modal-content .4s both;-webkit-animation-delay:.15s;animation-delay:.15s;padding:3px;font-family:brandon_textlight;}.navmsg__body-s,.navmsg__body-a{-webkit-animation:slide-modal-content .5s both;font-family:brandon_text_regularregular;animation:slide-modal-content .5s both;-webkit-animation-delay:.25s;animation-delay:.25s;padding:8px 2px;}.navmsg__header-s,.navmsg__close-s{background:#0f2a4a;color:#fff}.navmsg__close-s:hover,.navmsg__close-s:focus{background:rgba(15,42,74,.75)}.navmsg__content-s{background:#dff0d8;color:#0f2a4a}.navmsg__header-a,.navmsg__close-a{background:#8a5756;color:#fff}.navmsg__close-a:hover,.navmsg__close-a:focus{background:#c16361}.navmsg__content-a{background:#f2dede;color:#8a5756}.navmsg__header-s,.navmsg__header-a{text-align:center;font-size:2.4em;font-family:brandon_textlight;font-weight:300;line-height:1.2;padding:.4em}.navmsg__body{padding:24px}.navmsg__footer{text-align:center;height:28px;padding:2px 24px 14px}.dialog footer{height:28px !important;}</style>
<div class=navsac>
<script>
function navsac()
{
var x = document.getElementsByClassName('navsac');
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
}
</script>
<div class=dialog id=navmsg-nasa role=dialog>
<div class=navmsg__content-a>
<header class=navmsg__header-a>Champ manquant</header>
<div class=navmsg__body-a>Veuillez remplir le champ « Nom ».</div>
<footer class=navmsg__footer>
<button type=button class=navmsg__close-a button data-dismiss=alert onclick=navsac()>Fermer</button>
</footer>
</div>
</div>
</div>";
$melEmail = "<style>.dialog{-webkit-perspective:1300px;font-family:brandon_text_regularregular;perspective:1300px;position:fixed;top:50%;left:50%;width:50%;max-width:625px;min-width:240px;height:auto;z-index:2000;visibility:visible;-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);}.navmsg__content-s,.navmsg__content-a{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-transform:rotateY(-70deg);transform:rotateY(-70deg);transition:all .3s;opacity:0;border-radius:3px}.dialog{visibility:visible;}.navmsg__content-s,.navmsg__content-a{-webkit-transform:rotateY(0);transform:rotateY(0);opacity:1}.navmsg__close-s,.navmsg__close-a{-webkit-animation:slide-modal-content .4s both;animation:slide-modal-content .4s both;-webkit-animation-delay:.15s;animation-delay:.15s;padding:3px;font-family:brandon_textlight;}.navmsg__body-s,.navmsg__body-a{-webkit-animation:slide-modal-content .5s both;font-family:brandon_text_regularregular;animation:slide-modal-content .5s both;-webkit-animation-delay:.25s;animation-delay:.25s;padding:8px 2px;}.navmsg__header-s,.navmsg__close-s{background:#0f2a4a;color:#fff}.navmsg__close-s:hover,.navmsg__close-s:focus{background:rgba(15,42,74,.75)}.navmsg__content-s{background:#dff0d8;color:#0f2a4a}.navmsg__header-a,.navmsg__close-a{background:#8a5756;color:#fff}.navmsg__close-a:hover,.navmsg__close-a:focus{background:#c16361}.navmsg__content-a{background:#f2dede;color:#8a5756}.navmsg__header-s,.navmsg__header-a{text-align:center;font-size:2.4em;font-family:brandon_textlight;font-weight:300;line-height:1.2;padding:.4em}.navmsg__body{padding:24px}.navmsg__footer{text-align:center;height:28px;padding:2px 24px 14px}.dialog footer{height:28px !important;}</style>
<div class=navsac>
<script>
function navsac()
{
var x = document.getElementsByClassName('navsac');
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
}
</script>
<div class=dialog id=navmsg-nasa role=dialog>
<div class=navmsg__content-a>
<header class=navmsg__header-a>Champ manquant</header>
<div class=navmsg__body-a>Votre adresse e-mail n'est pas complète ou contient des caractères invalides.</div>
<footer class=navmsg__footer>
<button type=button class=navmsg__close-a button data-dismiss=alert onclick=navsac()>Fermer</button>
</footer>
</div>
</div>
</div>";
$melMsg = "<style>.dialog{-webkit-perspective:1300px;font-family:brandon_text_regularregular;perspective:1300px;position:fixed;top:50%;left:50%;width:50%;max-width:625px;min-width:240px;height:auto;z-index:2000;visibility:visible;-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);}.navmsg__content-s,.navmsg__content-a{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-transform:rotateY(-70deg);transform:rotateY(-70deg);transition:all .3s;opacity:0;border-radius:3px}.dialog{visibility:visible;}.navmsg__content-s,.navmsg__content-a{-webkit-transform:rotateY(0);transform:rotateY(0);opacity:1}.navmsg__close-s,.navmsg__close-a{-webkit-animation:slide-modal-content .4s both;animation:slide-modal-content .4s both;-webkit-animation-delay:.15s;animation-delay:.15s;padding:3px;font-family:brandon_textlight;}.navmsg__body-s,.navmsg__body-a{-webkit-animation:slide-modal-content .5s both;font-family:brandon_text_regularregular;animation:slide-modal-content .5s both;-webkit-animation-delay:.25s;animation-delay:.25s;padding:8px 2px;}.navmsg__header-s,.navmsg__close-s{background:#0f2a4a;color:#fff}.navmsg__close-s:hover,.navmsg__close-s:focus{background:rgba(15,42,74,.75)}.navmsg__content-s{background:#dff0d8;color:#0f2a4a}.navmsg__header-a,.navmsg__close-a{background:#8a5756;color:#fff}.navmsg__close-a:hover,.navmsg__close-a:focus{background:#c16361}.navmsg__content-a{background:#f2dede;color:#8a5756}.navmsg__header-s,.navmsg__header-a{text-align:center;font-size:2.4em;font-family:brandon_textlight;font-weight:300;line-height:1.2;padding:.4em}.navmsg__body{padding:24px}.navmsg__footer{text-align:center;height:28px;padding:2px 24px 14px}.dialog footer{height:28px !important;}</style>
<div class=navsac>
<script>
function navsac()
{
var x = document.getElementsByClassName('navsac');
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
}
</script>
<div class=dialog id=navmsg-nasa role=dialog>
<div class=navmsg__content-a>
<header class=navmsg__header-a>Champ manquant</header>
<div class=navmsg__body-a>Veuillez remplir le champ « Message ».</div>
<footer class=navmsg__footer>
<button type=button class=navmsg__close-a button data-dismiss=alert onclick=navsac()>Fermer</button>
</footer>
</div>
</div>
</div>";
$melEnv = "<style>.dialog{-webkit-perspective:1300px;font-family:brandon_text_regularregular;perspective:1300px;position:fixed;top:50%;left:50%;width:50%;max-width:625px;min-width:240px;height:auto;z-index:2000;visibility:visible;-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);}.navmsg__content-s,.navmsg__content-a{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-transform:rotateY(-70deg);transform:rotateY(-70deg);transition:all .3s;opacity:0;border-radius:3px}.dialog{visibility:visible;}.navmsg__content-s,.navmsg__content-a{-webkit-transform:rotateY(0);transform:rotateY(0);opacity:1}.navmsg__close-s,.navmsg__close-a{-webkit-animation:slide-modal-content .4s both;animation:slide-modal-content .4s both;-webkit-animation-delay:.15s;animation-delay:.15s;padding:3px;font-family:brandon_textlight;}.navmsg__body-s,.navmsg__body-a{-webkit-animation:slide-modal-content .5s both;font-family:brandon_text_regularregular;animation:slide-modal-content .5s both;-webkit-animation-delay:.25s;animation-delay:.25s;padding:8px 2px;}.navmsg__header-s,.navmsg__close-s{background:#0f2a4a;color:#fff}.navmsg__close-s:hover,.navmsg__close-s:focus{background:rgba(15,42,74,.75)}.navmsg__content-s{background:#dff0d8;color:#0f2a4a}.navmsg__header-a,.navmsg__close-a{background:#8a5756;color:#fff}.navmsg__close-a:hover,.navmsg__close-a:focus{background:#c16361}.navmsg__content-a{background:#f2dede;color:#8a5756}.navmsg__header-s,.navmsg__header-a{text-align:center;font-size:2.4em;font-family:brandon_textlight;font-weight:300;line-height:1.2;padding:.4em}.navmsg__body{padding:24px}.navmsg__footer{text-align:center;height:28px;padding:2px 24px 14px}.dialog footer{height:28px !important;}</style>
<div class=navsac>
<script>
function navsac()
{
var x = document.getElementsByClassName('navsac');
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
}
</script>
<div class=dialog id=navmsg-nasa role=dialog>
<div class=navmsg__content-s>
<header class=navmsg__header-s>Envoi réussi</header>
<div class=navmsg__body-s>Merci '.$Nom.' ! Votre e-mail a été correctement envoyé. Vous recevrez une réponse dès que possible !</div>
<footer class=navmsg__footer>
<button type=button class=navmsg__close-s button data-dismiss=alert onclick=navsac()>Fermer</button>
</footer>
</div>
</div>
</div>";
$melNenv = "<style>.dialog{-webkit-perspective:1300px;font-family:brandon_text_regularregular;perspective:1300px;position:fixed;top:50%;left:50%;width:50%;max-width:625px;min-width:240px;height:auto;z-index:2000;visibility:visible;-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);}.navmsg__content-s,.navmsg__content-a{-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-transform:rotateY(-70deg);transform:rotateY(-70deg);transition:all .3s;opacity:0;border-radius:3px}.dialog{visibility:visible;}.navmsg__content-s,.navmsg__content-a{-webkit-transform:rotateY(0);transform:rotateY(0);opacity:1}.navmsg__close-s,.navmsg__close-a{-webkit-animation:slide-modal-content .4s both;animation:slide-modal-content .4s both;-webkit-animation-delay:.15s;animation-delay:.15s;padding:3px;font-family:brandon_textlight;}.navmsg__body-s,.navmsg__body-a{-webkit-animation:slide-modal-content .5s both;font-family:brandon_text_regularregular;animation:slide-modal-content .5s both;-webkit-animation-delay:.25s;animation-delay:.25s;padding:8px 2px;}.navmsg__header-s,.navmsg__close-s{background:#0f2a4a;color:#fff}.navmsg__close-s:hover,.navmsg__close-s:focus{background:rgba(15,42,74,.75)}.navmsg__content-s{background:#dff0d8;color:#0f2a4a}.navmsg__header-a,.navmsg__close-a{background:#8a5756;color:#fff}.navmsg__close-a:hover,.navmsg__close-a:focus{background:#c16361}.navmsg__content-a{background:#f2dede;color:#8a5756}.navmsg__header-s,.navmsg__header-a{text-align:center;font-size:2.4em;font-family:brandon_textlight;font-weight:300;line-height:1.2;padding:.4em}.navmsg__body{padding:24px}.navmsg__footer{text-align:center;height:28px;padding:2px 24px 14px}.dialog footer{height:28px !important;}</style>
<div class=navsac>
<script>
function navsac()
{
var x = document.getElementsByClassName('navsac');
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none';
}
}
</script>
<div class=dialog id=navmsg-nasa role=dialog>
<div class=navmsg__content-a>
<header class=navmsg__header-a>Erreur d'envoi</header>
<div class=navmsg__body-a>Une erreur s'est produite lors de l'envoi de l'e-mail. Merci de réessayer.</div>
<footer class=navmsg__footer>
<button type=button class=navmsg__close-a button data-dismiss=alert onclick=navsac()>Fermer</button>
</footer>
</div>
</div>
</div>";
$Nom = $_POST['name'];
$Email = $_POST['email'];
$Message = $_POST['message'];
$Antispam = $_POST['firstname'];
$tokenID = $_POST['tokenID'];
$_SESSION['mailChamps'] = [
'name' => $Nom,
'email' => $Email,
'message' => $Message
];
$retour = array();
// Antispam
if (!empty($Antispam) || preg_match('#<a href#i', $Message) || preg_match('#boobs#i', $Message) || preg_match('#?#i', $Message))
exit('Fonction antispam');
// Si le champ nom est vide
if (empty($Nom)) :
echo
''.$melName.''
;
// Si le champ email est vide ou ne correspond pas à la syntaxe requise de type xxxx@xxxx.xxx
elseif (empty($Email) || !filter_var($Email, FILTER_VALIDATE_EMAIL)) :
echo
''.$melEmail.''
;
// Si le champ message est vide
elseif (empty($Message)) :
echo
''.$melMsg.''
;
endif;
$fomulaireErreurs = filter_var($retour);// A remplacer par quel script ?
if (empty($fomulaireErreurs)) :
$mailDestinataire = 'clemen.msg@gmail.com';
$mailContenu = array();
$mailContenu[] = 'Nom : '.$Nom.'<br />';
$mailContenu[] = 'Mail : '.$Email.'<br />';
$mailContenu[] = '<br />Message : <br />'.$Message;
$mailContenu = join($mailContenu);
$mailObjet = 'Mel de '.$Nom;
$mailHeaders = 'From: Clement Mel<clemen.msg@ndd.fr>'."\n";
$mailHeaders .= 'Reply-To: '.$Email."\n";
$mailHeaders .= 'MIME-Version: 1.0'."\n";
$mailHeaders .= 'Content-type: text/html; charset="utf-8"'."\n";
$mailHeaders .= 'Content-Transfer-Encoding: 8bit'."\n";
// Envoi du mail
if (mail($mailDestinataire, $mailObjet, $mailContenu, $mailHeaders)) :
echo
''.$melEnv.''
;
unset($_SESSION['mailChamps']);
else :
echo
''.$melNenv.''
;
endif;
endif;
?>