Nowwhat
18/05/2012, 01h17
Je repris ton fichier "test.php" - et après quelques modifications ça marche:
Code PHP:
$hasError = false;
$emailSent = false;
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!$hasError) {
$emailTo = "ton-mail@ton-site.tld";
$body = "Name: $name\n\nEmail: $email\n\nSubject: $subject\n\nComments:\n$comments";
$headers = "From: Site de l'APE $emailTo\nReply-To: $email";
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
if($hasError) { //If errors are found
echo "Merci de vérifier que tous les champs ont été correctement remplis.
";
}
?>
if($emailSent) { //If email is sent
echo "Votre email a été envoyé avec succès.
";
echo "Merci
$name d'avoir utilisé notre formulaire de contact.
Votre message a été envoyé avec succès et nous vous contacteront très prochainement.
Vous pouvez continuer votre navigation sur notre site !
";
}
?>