Erreur php champ obligatoire

Fermé
mailbox13630 Messages postés 127 Date d'inscription vendredi 1 décembre 2006 Statut Membre Dernière intervention 16 avril 2017 - 4 juin 2009 à 09:16
NookZ Messages postés 2138 Date d'inscription jeudi 29 janvier 2009 Statut Membre Dernière intervention 7 mars 2013 - 4 juin 2009 à 09:33
Bonjour,


Je ne parviens pas à résoudre mon code php traitement d'un formulaire pour que le champ email soit obligatoire.
Pouvez-vous m'aider?

Voici mon code:

<?php

$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$adresse = $_POST['adresse'];
$code_postal = $_POST['code_postal'];
$ville = $_POST['ville'];
$pays = $_POST['pays'];
$commentaire = $_POST['commentaire'];
$mail_contact = $_POST['mail'];



$email = (IsEmail($mail_contact)) ? $mail_contact : '';

if ($mail_contact !=" '')




$headers = "MIME-Version: 1.0\r\n";


$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";


$headers .= "From: $nom\r\nReply-to : <$mail_contact>\nX-Mailer:PHP";



$subject="Message venant du site";
$destinataire="email@gmail.com";
$body ="Message venant de : ".$prenom." ".$nom.".\n";
$body .= "Habitant ".$adresse.".\n";
$body .= "Code postal : ".$code_postal.".\n";
$body .= "Ville : ".$ville.".\n";
$body .= "Pays : ".$pays.".\n";
$body .= "Le message est le suivant : ".$commentaire.".\n";



mail($destinataire,$subject,$body,$headers);
echo "<h1><center>Le mail a bien été envoyé. Retour au <a href=http://www.monsite.com>site</a></center></h1>"

else
{
echo $message_formulaire_invalide.' <h1>Retour au <a href=http://www.monsite.com>site</a></center></h1>"'."\n";
};
};


?>

1 réponse

NookZ Messages postés 2138 Date d'inscription jeudi 29 janvier 2009 Statut Membre Dernière intervention 7 mars 2013 514
4 juin 2009 à 09:33
Bonjour,

déjà il manque des accolades :

if ($mail_contact !=" '') {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $nom\r\nReply-to : <$mail_contact>\nX-Mailer:PHP";

$subject="Message venant du site";
$destinataire="email@gmail.com";
$body ="Message venant de : ".$prenom." ".$nom.".\n";
$body .= "Habitant ".$adresse.".\n";
$body .= "Code postal : ".$code_postal.".\n";
$body .= "Ville : ".$ville.".\n";
$body .= "Pays : ".$pays.".\n";
$body .= "Le message est le suivant : ".$commentaire.".\n";


mail($destinataire,$subject,$body,$headers);
echo "<h1><center>Le mail a bien été envoyé. Retour au <a href=http://www.monsite.com>site</a></center></h1>"
}
else
{
echo $message_formulaire_invalide.' <h1>Retour au <a href=http://www.monsite.com>site</a></center></h1>"'."\n";
};
};


?>
0