include_once('config/conf.inc.php');
/*TABLEAUX ET FONCTIONS*/
$tab_session = array("societe","nom","prenom","fonction","activite","email","telephone","fax","numero","rue","code_postal","ville","pays","message");
$tab_mois = array("01"=>"Janvier","02"=>"Février","03"=>"Mars","04"=>"Avril","05"=>"Mai","06"=>"Juin","07"=>"Juillet","08"=>"Août","09"=>"Septembre","10"=>"Octobre","11"=>"Novembre","12"=>"Décembre");
function send_email ($mailto, $subject, $contenu, $from) {
//$from = "MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\nFrom: ".$from."\nReply-To: ".$from;
//mail($mailto, $subject, $contenu, $from);
require_once("include/swift/Swift.php");
require_once("include/swift/Swift/Connection/SMTP.php");
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
$message =& new Swift_Message($subject,$contenu,"text/html");
$swift->send($message, new Swift_Address($mailto), new Swift_Address($from,'site Infilter'));
$swift->disconnect();
}
/*TABLEAUX ET FONCTIONS*/
/*VERIFICATION DES CHAMPS DU POST*/
if(!empty($_POST)){
foreach($tab_session AS $cle){
$_SESSION['contact'][$cle] = $_POST[$cle];
}
$erreur = '';
if(empty($_POST['societe'])) $erreur .= "Veuillez saisir le nom de votre société.
";
if(empty($_POST['nom'])) $erreur .= "Veuillez saisir votre nom.
";
elseif(is_numeric($_POST['nom'])) $erreur .= "Votre nom est incorrect.
";
if(!empty($_POST['prenom']) && is_numeric($_POST['prenom'])) $erreur .= "Votre prénom est incorrect.
";
if(empty($_POST['email'])) $erreur .= "Veuillez saisir votre adresse email.
";
elseif(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-_.]?[0-9a-z])*\\.[a-z]{2,4}$",$_POST['email'])) $erreur .= "Votre adresse email est incorrecte.
";
if(empty($_POST['telephone'])) $erreur .= "Veuillez saisir votre numéro de téléphone.
";
if(!empty($_POST['code_postal']) && !is_numeric($_POST['code_postal'])) $erreur .= "Votre code postal est incorrect.
";
if(!empty($_POST['ville']) && is_numeric($_POST['ville'])) $erreur .= "Votre ville est incorrecte.
";
if(!empty($_POST['pays']) && is_numeric($_POST['pays'])) $erreur .= "Votre pays est incorrect.
";
if(empty($_POST['message'])) $erreur .= "Veuillez saisir votre message.
";
/*FIN DE GESTION DU POST*/
// si aucune erreur n'est apparue, on envoie le mail à partir du fichier modèle tpl_mail.html
if(empty($erreur)) {
$modele_mail = new template();
$modele_mail->ouvrir('tpl_mail.html');
$tableau_a_remplacer['{date}'] = date('d').' '.$tab_mois[date('m')].' '.date('Y');
$tableau_a_remplacer['{societe}'] = stripslashes($_POST['societe']);
if (!empty($_POST['prenom'])) $tableau_a_remplacer['{prenom}'] = stripslashes($_POST['prenom'])." ";
else $tableau_a_remplacer['{prenom}'] = "";
$tableau_a_remplacer['{nom}'] = stripslashes($_POST['nom']);
if(!empty($_POST['fonction'])) $tableau_a_remplacer['{fonction}'] = stripslashes($_POST['fonction']);
else $tableau_a_remplacer['{fonction}'] = "";
if(!empty($_POST['activite'])) $tableau_a_remplacer['{activite}'] = stripslashes($_POST['activite']);
else $tableau_a_remplacer['{activite}'] = "";
$tableau_a_remplacer['{email}'] = stripslashes($_POST['email']);
$tableau_a_remplacer['{telephone}'] = stripslashes($_POST['telephone']);
if(!empty($_POST['fax'])) $tableau_a_remplacer['{fax}'] = stripslashes($_POST['fax']);
else $tableau_a_remplacer['{fax}'] = "";
if(!empty($_POST['numero'])) $tableau_a_remplacer['{numero}'] = stripslashes($_POST['numero']);
else $tableau_a_remplacer['{numero}'] = "";
if(!empty($_POST['rue'])) $tableau_a_remplacer['{rue}'] = stripslashes($_POST[rue]);
else $tableau_a_remplacer['{rue}'] = "";
if(!empty($_POST['code_postal'])) $tableau_a_remplacer['{code_postal}'] = stripslashes($_POST['code_postal']);
else $tableau_a_remplacer['{code_postal}'] = "";
if(!empty($_POST['ville'])) $tableau_a_remplacer['{ville}'] = stripslashes($_POST['ville']);
else $tableau_a_remplacer['{ville}'] = "";
if(!empty($_POST['pays'])) $tableau_a_remplacer['{pays}'] = stripslashes($_POST['pays']);
else $tableau_a_remplacer['{pays}'] = "";
$tableau_a_remplacer['{message}'] = stripslashes($_POST['message']);
$modele_mail->remplacer($tableau_a_remplacer, $modele_mail->fichier);
// le fichier est editer, on l'envoi via la fonction send e_mail()
$mailto = "contact@devos.fr";
$suject = "Contact site Devos";
send_email ($mailto, $suject, $modele_mail->fichier_remplacer, $_POST['email']);
unset($_SESSION['contact']);
aller_url('merci.php');
exit();
}
else{
// il y a eu une erreur, on retourne au formulaire
$_SESSION['contact']['erreur'] = $erreur;
aller_url("contact.php");
exit();
}
// fin envoi
} else {
/*AFFICHAGE DU FORMULAIRE*/
$tpl = new template();
$tpl->ouvrir('menu.html');
$index = new template();
$index->ouvrir('contact.html');
// Affichage du message d'erreur si il y en a un.
if(!empty($_SESSION['contact']['erreur']))
$tableau_a_remplacer['{erreur}'] = ''.$_SESSION['contact']['erreur'].'
';
else $tableau_a_remplacer['{erreur}'] = '';
foreach($tab_session AS $cle){
if(!empty($_SESSION['contact'][$cle])) $tableau_a_remplacer['{'.$cle.'}'] = stripslashes($_SESSION['contact'][$cle]);
else $tableau_a_remplacer['{'.$cle.'}'] = '';
}
$tableau_a_remplacer['{menu}'] = $tpl->fichier;
$tableau_a_remplacer['{meta}'] = $meta;
foreach($tablink AS $cle => $val){
$tableau_a_remplacer[$cle] = $val;
}
$index->remplacer($tableau_a_remplacer, $index->fichier);
echo($index->fichier_remplacer);
}
/*END AFFICHAGE DU FORMULAIRE*/
?>