Modifier le traitement d'un formulaire
J'ai un petit formulaire html avec 3 champs qui doit etre traiter avec un script PHP mais, se dernier ca marche pas a 100% il ne traite pas les champs s'ils sont bien remplie et si l'adresse mail est correcte ou non? pouvez-vous m'aider a corriger se script?
Code html du petit formulaire :
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
| <form method="post" action="mail.php">
<table width="520" border="0" align="center" cellpadding="2" cellspacing="2">
<tbody>
<tr class="txt">
<td align="right"> </td>
<td width="5"> </td>
<td> </td>
</tr>
<tr class="txt">
<td align="right"><strong>Subject:<br />
</strong></td>
<td width="5"> </td>
<td><input size="50" name="subject" />
*</td>
</tr>
<tr class="txt">
<td align="right"><strong>E-mail Address:</strong></td>
<td width="5"> </td>
<td><input size="50" name="email" />
*</td>
</tr>
<tr class="txt">
<td align="right"> </td>
<td width="5"> </td>
<td> </td>
</tr>
<tr class="txt">
<td valign="top" align="right"><strong>Message:</strong></td>
<td width="5"> </td>
<td valign="top"><textarea name="contents" rows="8" cols="50"></textarea></td>
</tr>
<tr class="txt">
<td align="right"> </td>
<td width="5"> </td>
<td> </td>
</tr>
<tr class="txt">
<td align="right"> </td>
<td width="5"> </td>
<td><input name="submit" type="submit" value="Submit" /></td>
</tr>
<tr class="txt">
<td align="right"> </td>
<td width="5"> </td>
<td> </td>
</tr>
</tbody>
</table>
</form> |
Script 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
| <?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$destinataire = "*****@gmail.com";
$email=$_POST["email"];
//$headers = 'From: webmaster@example.com ' . "\r\n" ;
$from=htmlentities("From: $email" . "\r\n") ;
$subject=stripslashes(htmlentities($_POST["subject"]));
//$name=$_POST["name"];
//$website=$_POST["website"];
$contents=stripslashes(htmlentities($_POST["contents"]));
$regex = '/^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$/i';
if (!preg_match($regex, $email))
{
echo 'Adresse' .$email. 'n est pas valide';
}
elseif (trim($contents)=="")
{
echo "Veuillez écrire votre message";
}
if (mail($destinataire, $email, $sujet, $contents, $from)) // Envoi du message
{
echo 'Votre message a bien été envoyé ';
}
else // Non envoyé
{
echo "Votre message n'a pas pu être envoyé";
}
?> |