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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| <?php
session_start();
$homepage = 'http://localhost/email/';
$yourmail = '@mail.com';
$theform = 'http://localhost/wmail/email.php';
$prefixe = 'Je désire :';
$vop_a = htmlto("item 1");
$vop_b = htmlto("item 2");
$vop_c = htmlto("item 3");
$vop_d = htmlto("item 4");
$vop_e = htmlto("item 5");
$vop_f = htmlto("item 6");
$vop_g = htmlto("item 7");
$vop_h = htmlto("item 8");
$vop_i = htmlto("item 9");
$vop_j = htmlto("item 10");
$titlesubject = 'Provenance de mon site';
//passe le test security compass:
function htmlto($str){
$str = trim($str);
$str = stripslashes($str);
$str = htmlspecialchars($str,ENT_QUOTES);
$str = str_replace("<",NULL,$str);
$str = str_replace(">",NULL,$str);
$str = str_replace("=",NULL,$str);
$str = str_replace("\\",NULL,$str);
$str = str_replace("/",NULL,$str);
$str = str_replace(";",NULL,$str);
return $str ;
}
//defini le captcha couleur
$couleur = array("yellow","green","blue","red","gray","pink","black");
$color = $couleur[rand(0,5)];
if($color == "yellow") $code = "jaune";
if($color == "green") $code = "vert";
if($color == "blue") $code = "bleu";
if($color == "red") $code = "rouge";
if($color == "gray") $code = "gris";
if($color == "pink") $code = "rose";
if($color == "black") $code = "noir";
$captcha = '<div style="width:20px;"><div style="float:right;width:20px;height:20px;background-color:'.$color.'"></div></div>';
if (isset($_POST['envoye'])){
$civilite = ucfirst(htmlto($_POST['civilite']));
$nom = ucfirst(htmlto($_POST['nom']));
$pre = ucfirst(htmlto($_POST['pre']));
$expediteur = htmlto($_POST['email']);
$sujet = htmlto($_POST['sujet']);
$message = htmlto($_POST['message']);
//defini les options
$op_z = (isset($_POST['op_a'])) ? htmlto($_POST['op_a'])."\r\n" : null;
$op_z .= (isset($_POST['op_b'])) ? htmlto($_POST['op_b'])."\r\n" : null;
$op_z .= (isset($_POST['op_c'])) ? htmlto($_POST['op_c'])."\r\n" : null;
$op_z .= (isset($_POST['op_d'])) ? htmlto($_POST['op_d'])."\r\n" : null;
$op_z .= (isset($_POST['op_e'])) ? htmlto($_POST['op_e'])."\r\n" : null;
$op_z .= (isset($_POST['op_f'])) ? htmlto($_POST['op_f'])."\r\n" : null;
$op_z .= (isset($_POST['op_g'])) ? htmlto($_POST['op_g'])."\r\n" : null;
$op_z .= (isset($_POST['op_h'])) ? htmlto($_POST['op_h'])."\r\n" : null;
$op_z .= (isset($_POST['op_i'])) ? htmlto($_POST['op_i'])."\r\n" : null;
$op_z .= (isset($_POST['op_j'])) ? htmlto($_POST['op_j'])."\r\n" : null;
if(isset($_POST['token'], $_SESSION['token'])){
if($_POST['token'] == $_SESSION['token']){
if(isset($_POST['color'], $_SESSION['color'])){
if($_POST['color'] == $_SESSION['color']){
echo '<p style="color:red">Captcha OK</p>';
$regex_mail = '/^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$/i';
$regex_head = '/[\n\r]/';
if($_SERVER['HTTP_REFERER'] != $theform ){
header($homepage);
}
elseif (empty($civilite)
|| empty($nom)
|| empty($pre)
|| empty($expediteur)
|| empty($sujet)){
$alert = 'Tous les champs doivent être renseignés';
}
//ceci qui fait sujet du poste:
$lenMsg = strlen($message);
$lenOpz = strlen($op_z);
if ( ! ($lenMsg || $lenOpz)) {
$alert = ($lenMsg && ($lenMsg < 20))
? 'Message trop court'
: 'Il faut indiquer une option ou/et un message';
}
elseif (!preg_match($regex_mail, $expediteur)){
$alert = 'L\'adresse '.$expediteur.' n\'est pas valide';
}
elseif (preg_match($regex_head, $expediteur)
|| preg_match($regex_head, $nom)
|| preg_match($regex_head, $pre)
|| preg_match($regex_head, $sujet)){
$alert = 'En-têtes interdites dans les champs du formulaire';
}
elseif (!isset($_COOKIE['sent'])){
$to = $yourmail;
$msg = 'Bonjour,'."\r\n\r\n";
$msg .= 'Ce mail a été envoyé depuis '.$_SERVER['HTTP_HOST'].' par '.$civilite.'. '.$pre.' '.$nom."\r\n\r\n";
$msg .= 'Voici le message qui vous est adressé :'."\r\n";
$msg .= '******************************************************'."\r\n";
$msg .= $prefixe."\r\n";
$msg .= $op_z."\r\n";
$msg .= 'Message :'."\r\n";
$msg .= $message."\r\n";
$msg .= '******************************************************'."\r\n";
// permettre les apostrophes
$nom = preg_replace("/(')/",chr(39),"$nom");
$pre = preg_replace("/(')/",chr(39),"$pre");
$sujet = preg_replace("/(')/",chr(39),"$sujet");
$msg = preg_replace("/(')/",chr(39),"$msg");
$headers = 'From: '.$pre.' '.$nom.' <'.$expediteur.'>'."\r\n\r\n";
if (mail($to, $sujet, $msg, $headers)){
$alert = 'E-mail envoyé avec succès';
unset($_POST);
} //mail
else{ $alert = 'Erreur d\'envoi de l\'e-mail'; }
}else{ unset($_POST); } //cookieisset
}else{ echo '<p style="color:red">Captcha non OK</p>'; } //color
} //colorisset
} //token
} //tokenisset
} //envoyéisset
if (!empty($alert)){
echo '<p style="color:red">'.$alert.'</p>';
}
unset($_SESSION['color']);
$_SESSION['color'] = $code;
unset($_SESSION['token']);
$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;
?>
<form action="<?php echo $theform; ?>" method="POST">
<fieldset>
<legend><strong>Nous contacter</strong></legend><p>
<table border="0">
<tr>
<td colspan="4">
<label for="civilite">Civilité :</label>
<select id="civilite" name="civilite">
<option value="mr" <?php if (!isset($_POST['civilite']) || $_POST['civilite'] == 'mr'){ echo ' selected="selected"'; } ?>>Monsieur</option>
<option value="mme" <?php if (isset($_POST['civilite']) && $_POST['civilite'] == 'mme'){ echo ' selected="selected"'; } ?>>Madame</option>
<option value="mlle" <?php if (isset($_POST['civilite']) && $_POST['civilite'] == 'mlle'){ echo ' selected="selected"'; } ?>>Mademoiselle</option>
</select>
</td>
</tr>
<tr>
<td colspan="4">
<label for="nom">NOM :</label>
<input class="form" type="text" id="nom" name="nom" value="<?php echo (isset($_POST['nom'])) ? $nom : '' ?>" size="33" />
</td>
</tr>
<tr>
<td colspan="4">
<label for="nom">Prénom :</label>
<input class="form" type="text" id="pre" name="pre" value="<?php echo (isset($_POST['pre'])) ? $pre : '' ?>" size="33" />
</td>
</tr>
<tr>
<td colspan="4">
<label for="email">Courriel :</label>
<input class="form" type="email" id="email" name="email" value="<?php echo (isset($_POST['email'])) ? $expediteur : '' ?>" size="33" />
</td>
</tr>
<tr>
<td colspan="4">
<label for="sujet">Sujet :</label>
<input class="form" type="text" id="sujet" name="sujet" value="<?php echo (isset($_POST['sujet'])) ? $sujet : $titlesubject; ?>" size="33" readonly />
</td>
</tr>
<tr>
<td colspan="4"><?php echo $prefixe.'<br><br>'; ?>
<div class="opz">
<input type="checkbox" name="op_a" id="op_a" value="<?php echo $vop_a; ?>" /> <label for="op_a"><?php echo $vop_a; ?></label><br><br>
<input type="checkbox" name="op_b" id="op_b" value="<?php echo $vop_b; ?>" /> <label for="op_b"><?php echo $vop_b; ?></label><br>
<input type="checkbox" name="op_c" id="op_c" value="<?php echo $vop_c; ?>" /> <label for="op_c"><?php echo $vop_c; ?></label><br>
<input type="checkbox" name="op_d" id="op_d" value="<?php echo $vop_d; ?>" /> <label for="op_d"><?php echo $vop_d; ?></label><br>
<input type="checkbox" name="op_e" id="op_e" value="<?php echo $vop_e; ?>" /> <label for="op_e"><?php echo $vop_e; ?></label><br><br>
<input type="checkbox" name="op_f" id="op_f" value="<?php echo $vop_f; ?>" /> <label for="op_f"><?php echo $vop_f; ?></label><br>
<input type="checkbox" name="op_g" id="op_g" value="<?php echo $vop_g; ?>" /> <label for="op_g"><?php echo $vop_g; ?></label><br>
<input type="checkbox" name="op_h" id="op_h" value="<?php echo $vop_h; ?>" /> <label for="op_h"><?php echo $vop_h; ?></label><br>
<input type="checkbox" name="op_i" id="op_i" value="<?php echo $vop_i; ?>" /> <label for="op_i"><?php echo $vop_i; ?></label><br><br>
<input type="checkbox" name="op_j" id="op_j" value="<?php echo $vop_j; ?>" /> <label for="op_j"><?php echo $vop_j; ?></label><br>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<label for="textarea_1">Le message</label><br>
<textarea class="form" id="textarea_1" name="message" cols="55" rows="4"><?php echo (isset($_POST['message'])) ? $message : '' ?></textarea>
Il vous reste <span id="carac_reste_textarea_1"></span> caractères.
<script type="text/javascript">
<!--
maxlength_textarea('textarea_1','carac_reste_textarea_1',250);
-->
</script>
</td>
</tr>
<tr>
<td width="30%" align="center">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input style="width:66px" type="submit" name="envoye" value="Envoyer" />
<input style="width:66px" type="reset" name="annuler" value="Annuler" />
</td>
<td width="36%" align="center">
Quelle est cette couleur?
</td>
<td width="5%" align="center">
<?php echo $captcha; ?>
</td>
<td width="15%" align="center">
<input class="form" style="width:75px" type="text" id="color" name="color" value="" size="10" />
</td>
</tr>
</table>
</fieldset>
</form> |
Partager