Formulaire "sans Mysql/direct dans boite mail"
Bonjour,
Je me lance dans la création d'un site. J'ai mis longtemps à trouver la solution à l'intitulé de la discution. Mais a force de recherche et de test j'ai trouvé un code htlm et php qui fonctionne l'un avec l'autre. Le soucis et que je n'arrive pas à rendre le formulaire htlm plus esthétique (zone de texte alignés)tout en gardant ses fonctions.
Code du formulaire sur page HTLM:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <form action="traitement.php" method="post">
<p>
<strong>Nom<span style="color: #ff0000;">*</span> :</strong> <label for="nom"> </label> <input id="nom" name="nom" size="28" type="text" />
<strong>Prénom :</strong> <label for="prenom"></label> <input id="prenom" name="prenom" size="27" type="text" /> <br /><br />
<strong> Société : </strong><br /> <label for="societe"> </label> <input id="societe" name="societe" size="81" type="text" /> <br /><br />
<strong> RCS : </strong><br /> <label for="rcs"> </label> <input id="rcs" name="rcs" size="81" type="text" /> <br /><br />
<strong>Adresse : </strong><br /> <label for="adresse"></label> <input id="adresse" name="adresse" size="81" type="text" /> <br /><br />
<strong>Code Postal :</strong> <label for="code"></label> <input id="code" name="code" size="13" type="text" />
<strong>Ville : </strong> <label for="ville"></label> <input id="ville" name="ville" size="39" type="text" /> <br /><br />
<strong>Téléphone<span style="color: #ff0000;">*</span> :<label for="telephone"></label></strong> <input id="telephone" name="telephone" size="27" type="text" />
<strong>Fax :</strong> <label for="fax"></label> <input id="fax" name="fax" size="27" type="text" /> <br /> <br />
<strong>Mail <span style="color: #ff0000;">*</span> : </strong><br /> <label for="mail"> </label><input id="mail" name="mail" size="81" type="text" /></p>
<p>Pour quelle raison nous contactez-vous ?</p>
<label for="motif"></label> <select id="motif" name="motif"> <option value="reglement">Pour un renseignement</option>
<option value="enquete_commerciales">Pour une vidéo</option>
<option value="enquete_civile">Pour un article</option>
<option value="recouvrement">Pour autre chose</option>
</select>
<p>Message <span style="color: #ff0000;">*</span> :</p>
<p><label for="message"></label> <textarea id="message" cols="52" rows="7" name="message"></textarea></p>
<input type="reset" value="Effacer" /> <input type="submit" value="Envoyer" />
<p> </p>
</form> |
Code pour page PHP:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| <?php
/* Récupération des informations du formulaire*/
if (get_magic_quotes_gpc())
{
$nom = stripslashes(trim($_POST['nom']));
$prenom = stripslashes(trim($_POST['prenom']));
$dossier = stripslashes(trim($_POST['dossier']));
$societe = stripslashes(trim($_POST['societe']));
$rcs = stripslashes(trim($_POST['rcs']));
$code = stripslashes(trim($_POST['code']));
$ville = stripslashes(trim($_POST['ville']));
$telephone = stripslashes(trim($_POST['telephone']));
$fax = stripslashes(trim($_POST['fax']));
$mail = stripslashes(trim($_POST['mail']));
$motif = stripslashes(trim($_POST['motif']));
$message = stripslashes(trim($_POST['message']));
}
else
{
$nom = trim($_POST['nom']);
$prenom = trim($_POST['prenom']);
$dossier = trim($_POST['dossier']);
$societe = trim($_POST['societe']);
$rcs = trim($_POST['rcs']);
$adresse = trim($_POST['adresse']);
$code = trim($_POST['code']);
$ville = trim($_POST['ville']);
$telephone = trim($_POST['telephone']);
$fax = trim($_POST['fax']);
$mail = trim($_POST['mail']);
$motif = trim($_POST['motif']);
$message = trim($_POST['message']);
}
/*Vérifie si l'adresse mail est au bon format */
$regex_mail = '/^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$/i';
/*Verifie qu il n y est pas d en tête dans les données*/
$regex_head = '/[\n\r]/';
/*Vérifie qu il n y est pas d erreur dans adresse mail*/
if (!preg_match($regex_mail, $mail))
{
$alert = 'L\'adresse '.$mail.' n\'est pas valide';
}
else
{
$courriel = 1;
}
/* On affiche l'erreur s'il y en a une */
if (!empty($alert))
{
$courriel = 0;
}
/* On vérifie qu'il n'y a aucun header dans les champs */
if (preg_match($regex_head, $nom)
|| preg_match($regex_head, $prenom)
|| preg_match($regex_head, $dossier)
|| preg_match($regex_head, $societe)
|| preg_match($regex_head, $rcs)
|| preg_match($regex_head, $adresse)
|| preg_match($regex_head, $code)
|| preg_match($regex_head, $ville)
|| preg_match($regex_head, $telephone)
|| preg_match($regex_head, $fax)
|| preg_match($regex_head, $mail)
|| preg_match($regex_head, $motif)
|| preg_match($regex_head, $message))
{
$alert = 'En-têtes interdites dans les champs du formulaire';
}
else
{
$header = 1;
}
/* On affiche l'erreur s'il y en a une */
if (!empty($alert))
{
$header = 0;
}
if (empty($telephone)
|| empty($nom)
|| empty($message))
{
$alert = 'Tous les champs doivent être renseignés';
}
else
{
$renseigne = 1;
}
/* On affiche l'erreur s'il y en a une */
if (!empty($alert))
{
$renseigne = 0;
}
/* Si les variables sont bonne */
if ($renseigne == 1 AND $header == 1 AND $courriel == 1)
{
/*Envoi du mail*/
/*Le destinataire*/
$to=" <a href="mailto:demo@fafa-informatique.comCet">demo@fafa-informatique.comCet</a>te adresse email est protégée contre les robots des spammeurs, vous devez activer Javascript pour la voir. ";
/*Le sujet du message qui apparaitra*/
$sujet="Message depuis le site";
$msg = '';
/*Le message en lui même*/
/*$msg = 'Mail envoye depuis le site' "\r\n\r\n";*/
$msg .= 'Nom : '.$nom."\r\n\r\n";
$msg .= 'Prenom : '.$prenom."\r\n\r\n";
$msg .= 'Dossier : '.$dossier."\r\n\r\n";
$msg .= 'Societe : '.$societe."\r\n\r\n";
$msg .= 'RCS : '.$rcs."\r\n\r\n";
$msg .= 'Adresse : '.$adresse."\r\n\r\n";
$msg .= 'Code : '.$code."\r\n\r\n";
$msg .= 'Ville : '.$ville."\r\n\r\n";
$msg .= 'Telephone : '.$telephone."\r\n\r\n";
$msg .= 'Fax : '.$fax."\r\n\r\n";
$msg .= 'Mail : '.$mail."\r\n\r\n";
$msg .= 'Motif : '.$motif."\r\n\r\n";
$msg .= 'Message : '.$message."\r\n\r\n";
/*Les en-têtes du mail*/
$headers = 'From: MESSAGE DU SITE FAFA<demo@fafa-informatique>'."\r\n";
$headers .= "\r\n";
/*L'envoi du mail - Et page de redirection*/
mail($to, $sujet, $msg, $headers);
header('Location:<a href="http://www.fafa-informatique.com');" target="_blank">http://www.fafa-informatique.com');</a>
}
else
{
header('Location:<a href="http://www.fafa-informatique.com');" target="_blank">http://www.fafa-informatique.com');</a>
}
?> |
J'ai mis toutes les informations directement en copier coller car je pense que sa pourra servir a d'autre débutants, vus le temps que j'ai pris pour trouver une solution viable. L'origine du code viens de cette page:
http://www.artup-concept.com/formula...ct-en-php.html
J'espère avoir été claire, merci d'avance.