par
david_vidda » 01 avr. 2010, 22:58
Bonsoir merci d avoir pris le temp de m éxpliquer

alors j ai pas une page avec ce script la que j ai nomé en php :
<?php
class FormMailDrk
{
// déclaration des propriétés
private $count;
private $message;
private $verif;
private $email;
private $sujet;
private $nom;
private $header;
private $destinataire;
private $max_email = 50;
private $max_sujet = 50;
private $max_nom = 50;
private $max_message = 500;
private $array_post;
private $send;
private $mess;
public function __construct($count, $max_email, $max_sujet, $max_nom, $max_message) {
$this->send = false;
$this->mess = false;
if (func_num_args() !== 5) {
$this->verif = 'Nombre d\'arguments invalide';
} else if (!empty($_POST) && !$this->no_strings()) {
$this->count = (int) $count;
$this->max_email = (int) $max_email;
$this->max_sujet = (int) $max_sujet;
$this->max_nom = (int) $max_nom;
$this->max_message = (int) $max_message;
// Constante PHP_VERSION_ID
if (!defined('PHP_VERSION_ID')) {
list($major, $minor, $release) = explode('.', PHP_VERSION, 3);
$release = (int)$release;
if ($release < 10) $release = "0$release";
define('PHP_VERSION_ID', "{$major}0{$minor}$release");
}
$this->clean_post();
} else {
$this->verif = null;
}
}
private function clean_post() {
if (count($_POST) === $this->count) {
$_POST = $this->m_verifgpc();
$_POST = array_map('trim', $_POST);
$this->message = isset($_POST['message']) ? $_POST['message'] : null;
$_POST = $this->m_antispam();
if (!$this->m_empty() && isset($this->message)) {
$this->mess = true;
$this->verif_form();
} else {
$this->verif = 'Veuillez remplir tous les champs du formulaire, svp';
}
} else {
$this->verif = 'Nombre de champs envoyés invalide';
}
}
private function verif_form() {
$this->sujet = isset($_POST['sujet']) ? $_POST['sujet'] : null;
$this->nom = isset($_POST['nom']) ? $_POST['nom'] : null;
$this->email = isset($_POST['email']) ? $_POST['email'] : null;
if (!isset($this->sujet) || !isset($this->nom)) {
$this->verif = 'Veuillez remplir tous les champs du formulaire, svp';
} else if ($this->verif_mail($this->email)) {
$this->set_taille();
} else {
$this->verif = 'Email Invalide: ' . $this->email;
}
}
private function set_taille() {
$this->message = substr($this->message, 0, $this->max_message);
$this->sujet = substr($this->sujet, 0, $this->max_sujet);
$this->nom = substr($this->nom, 0, $this->max_nom);
$this->set_header();
}
private function set_header() {
$this->header = 'From: ' . $this->email . "\n";
$this->header .= 'Reply-To: ' . $this->email . "\n";
$this->header .= 'X-Mailer: PHP/' . PHP_VERSION . "\n";
$this->header .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$this->set_array();
}
private function set_array() {
$this->array_post = array('nom' => $this->nom,
'sujet' => $this->sujet,
'email' => $this->email,
'message' => $this->message,
'header' => $this->header);
$this->send = true;
}
private function m_verifgpc() {
return (PHP_VERSION_ID < 60000 && get_magic_quotes_gpc())
? array_map('stripslashes', $_POST) : $_POST;
}
private function m_empty() {
foreach($_POST as $index => $valeur) {
if (empty($valeur)) return true;
}
return false;
}
private function m_antispam() {
$valid_array = array(chr(10), chr(13));
foreach($_POST as $index => $valeur) {
$_POST[$index] = str_replace($valid_array, '', $valeur);
}
return $_POST;
}
private function no_strings() {
foreach($_POST as $index => $valeur) {
if (!is_string($valeur)) return true;
}
return false;
}
private function is_win() {
return (substr(PHP_OS, 0, 3) === 'WIN');
}
private function verif_safemode() {
if (PHP_VERSION_ID < 60000) {
$safe_mode = ini_get('safe_mode');
return $safe_mode;
} else {
return false;
}
}
// Vérifier la syntaxe d'un email
public function verif_mail($email = null) {
if ($this->mess) {
$email = (string) $email;
if (strlen($email) < $this->max_email && preg_match('#^[a-z0-9]+([-_.][a-z0-9]+)*@[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,4}$#', $email)) {
if ($this->is_win() && PHP_VERSION_ID < 50300) {
return true;
} else {
$email = end(explode('@', $email));
return checkdnsrr($email, 'NS');
}
} else {
return false;
}
}
}
public function send_mail($destinataire = null) {
if ($this->send) {
$this->destinataire = (string) $destinataire;
if ($this->verif_mail($this->destinataire)) {
$envoyer = ($this->verif_safemode())
? mail($this->destinataire, $this->sujet, $this->message, $this->header)
: mail($this->destinataire, $this->sujet, $this->message, $this->header, "-f{$this->email}");
$this->verif = ($envoyer) ? 'Mail envoyé' : 'Erreur critique';
} else {
$this->verif = 'Email Destinataire invalide';
}
}
}
public function __get($name = null) {
if ($this->send) {
$name = (string) $name;
if (array_key_exists($name, $this->array_post)) {
return $this->array_post[$name];
} else {
$this->verif = 'Nom de champ inconnu';
}
} else if ($this->mess && $name === 'message'){
$this->verif = null;
return $this->message;
}
}
public function __toString() {
return '<em>' . $this->verif . '</em>';
}
}
// Exemple 1 (Utilisation complète de la class) -> Traiter et envoyer
// Initialisation (nombre de posts, taille max(email, sujet, nom, message))
// Nommer les champs de votre formulaire: email, sujet, nom, message.
$obj = new FormMailDrk(5, 50, 50, 50, 500);
// Envoie de l'email
$obj->send_mail('
[email protected]');
?>
Et une autre page que j ai fais en html :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulaire de contact</title>
</head>
<body style="color:steelblue;">
<!-- Début du DIV -->
<div style="margin-top:30px;"><form action="#" method="post">
<table style="margin-left:auto; margin-right:auto; padding:6px;
border:1px inset lavender; background-color:#F5F5F5;" cellpadding="2"><tr>
<td style="text-align:center; padding-bottom:15px;" colspan="2">Formulaire de contact</td>
</tr><tr><td>Nom</td>
<td><input type="text" name="nom" maxlength="50" /></td>
</tr><tr><td>Email</td>
<td><input type="text" name="email" maxlength="50" /> (minuscules)</td>
</tr><tr><td>Sujet</td>
<td><input type="text" name="sujet" maxlength="50" /></td>
</tr><tr><td>Qui suis-je?</td>
<td><select name="qui">
<option value="hybride">Je ne sais pas</option>
<option value="robot">Robot</option>
<option value="humain">Humain</option>
</select></td>
</tr><tr><td>Message</td>
<td><textarea rows="10" cols="40" name="message"></textarea></td>
</tr><tr><td><input type="submit" value="Envoyer" />
</td></tr></table></form><p style="text-align:center; font-size:10px;">Class Php Mail
(Dr@ke) (<a href="
http://palacesec.freehostia.com/">http: ... m/</a>)</p>
<p><?php print($obj); ?></p></div>
<!-- Fin du Div -->
</body></html>
Mais comme ca malheuresement ca fonctionne toujours pas je dois faire quelques choses de travers obligé ??
Bonsoir merci d avoir pris le temp de m éxpliquer :)
alors j ai pas une page avec ce script la que j ai nomé en php :
<?php
class FormMailDrk
{
// déclaration des propriétés
private $count;
private $message;
private $verif;
private $email;
private $sujet;
private $nom;
private $header;
private $destinataire;
private $max_email = 50;
private $max_sujet = 50;
private $max_nom = 50;
private $max_message = 500;
private $array_post;
private $send;
private $mess;
public function __construct($count, $max_email, $max_sujet, $max_nom, $max_message) {
$this->send = false;
$this->mess = false;
if (func_num_args() !== 5) {
$this->verif = 'Nombre d\'arguments invalide';
} else if (!empty($_POST) && !$this->no_strings()) {
$this->count = (int) $count;
$this->max_email = (int) $max_email;
$this->max_sujet = (int) $max_sujet;
$this->max_nom = (int) $max_nom;
$this->max_message = (int) $max_message;
// Constante PHP_VERSION_ID
if (!defined('PHP_VERSION_ID')) {
list($major, $minor, $release) = explode('.', PHP_VERSION, 3);
$release = (int)$release;
if ($release < 10) $release = "0$release";
define('PHP_VERSION_ID', "{$major}0{$minor}$release");
}
$this->clean_post();
} else {
$this->verif = null;
}
}
private function clean_post() {
if (count($_POST) === $this->count) {
$_POST = $this->m_verifgpc();
$_POST = array_map('trim', $_POST);
$this->message = isset($_POST['message']) ? $_POST['message'] : null;
$_POST = $this->m_antispam();
if (!$this->m_empty() && isset($this->message)) {
$this->mess = true;
$this->verif_form();
} else {
$this->verif = 'Veuillez remplir tous les champs du formulaire, svp';
}
} else {
$this->verif = 'Nombre de champs envoyés invalide';
}
}
private function verif_form() {
$this->sujet = isset($_POST['sujet']) ? $_POST['sujet'] : null;
$this->nom = isset($_POST['nom']) ? $_POST['nom'] : null;
$this->email = isset($_POST['email']) ? $_POST['email'] : null;
if (!isset($this->sujet) || !isset($this->nom)) {
$this->verif = 'Veuillez remplir tous les champs du formulaire, svp';
} else if ($this->verif_mail($this->email)) {
$this->set_taille();
} else {
$this->verif = 'Email Invalide: ' . $this->email;
}
}
private function set_taille() {
$this->message = substr($this->message, 0, $this->max_message);
$this->sujet = substr($this->sujet, 0, $this->max_sujet);
$this->nom = substr($this->nom, 0, $this->max_nom);
$this->set_header();
}
private function set_header() {
$this->header = 'From: ' . $this->email . "\n";
$this->header .= 'Reply-To: ' . $this->email . "\n";
$this->header .= 'X-Mailer: PHP/' . PHP_VERSION . "\n";
$this->header .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$this->set_array();
}
private function set_array() {
$this->array_post = array('nom' => $this->nom,
'sujet' => $this->sujet,
'email' => $this->email,
'message' => $this->message,
'header' => $this->header);
$this->send = true;
}
private function m_verifgpc() {
return (PHP_VERSION_ID < 60000 && get_magic_quotes_gpc())
? array_map('stripslashes', $_POST) : $_POST;
}
private function m_empty() {
foreach($_POST as $index => $valeur) {
if (empty($valeur)) return true;
}
return false;
}
private function m_antispam() {
$valid_array = array(chr(10), chr(13));
foreach($_POST as $index => $valeur) {
$_POST[$index] = str_replace($valid_array, '', $valeur);
}
return $_POST;
}
private function no_strings() {
foreach($_POST as $index => $valeur) {
if (!is_string($valeur)) return true;
}
return false;
}
private function is_win() {
return (substr(PHP_OS, 0, 3) === 'WIN');
}
private function verif_safemode() {
if (PHP_VERSION_ID < 60000) {
$safe_mode = ini_get('safe_mode');
return $safe_mode;
} else {
return false;
}
}
// Vérifier la syntaxe d'un email
public function verif_mail($email = null) {
if ($this->mess) {
$email = (string) $email;
if (strlen($email) < $this->max_email && preg_match('#^[a-z0-9]+([-_.][a-z0-9]+)*@[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,4}$#', $email)) {
if ($this->is_win() && PHP_VERSION_ID < 50300) {
return true;
} else {
$email = end(explode('@', $email));
return checkdnsrr($email, 'NS');
}
} else {
return false;
}
}
}
public function send_mail($destinataire = null) {
if ($this->send) {
$this->destinataire = (string) $destinataire;
if ($this->verif_mail($this->destinataire)) {
$envoyer = ($this->verif_safemode())
? mail($this->destinataire, $this->sujet, $this->message, $this->header)
: mail($this->destinataire, $this->sujet, $this->message, $this->header, "-f{$this->email}");
$this->verif = ($envoyer) ? 'Mail envoyé' : 'Erreur critique';
} else {
$this->verif = 'Email Destinataire invalide';
}
}
}
public function __get($name = null) {
if ($this->send) {
$name = (string) $name;
if (array_key_exists($name, $this->array_post)) {
return $this->array_post[$name];
} else {
$this->verif = 'Nom de champ inconnu';
}
} else if ($this->mess && $name === 'message'){
$this->verif = null;
return $this->message;
}
}
public function __toString() {
return '<em>' . $this->verif . '</em>';
}
}
// Exemple 1 (Utilisation complète de la class) -> Traiter et envoyer
// Initialisation (nombre de posts, taille max(email, sujet, nom, message))
// Nommer les champs de votre formulaire: email, sujet, nom, message.
$obj = new FormMailDrk(5, 50, 50, 50, 500);
// Envoie de l'email
$obj->send_mail('
[email protected]');
?>
Et une autre page que j ai fais en html :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulaire de contact</title>
</head>
<body style="color:steelblue;">
<!-- Début du DIV -->
<div style="margin-top:30px;"><form action="#" method="post">
<table style="margin-left:auto; margin-right:auto; padding:6px;
border:1px inset lavender; background-color:#F5F5F5;" cellpadding="2"><tr>
<td style="text-align:center; padding-bottom:15px;" colspan="2">Formulaire de contact</td>
</tr><tr><td>Nom</td>
<td><input type="text" name="nom" maxlength="50" /></td>
</tr><tr><td>Email</td>
<td><input type="text" name="email" maxlength="50" /> (minuscules)</td>
</tr><tr><td>Sujet</td>
<td><input type="text" name="sujet" maxlength="50" /></td>
</tr><tr><td>Qui suis-je?</td>
<td><select name="qui">
<option value="hybride">Je ne sais pas</option>
<option value="robot">Robot</option>
<option value="humain">Humain</option>
</select></td>
</tr><tr><td>Message</td>
<td><textarea rows="10" cols="40" name="message"></textarea></td>
</tr><tr><td><input type="submit" value="Envoyer" />
</td></tr></table></form><p style="text-align:center; font-size:10px;">Class Php Mail
(Dr@ke) (<a href="http://palacesec.freehostia.com/">http://palacesec.freehostia.com/</a>)</p>
<p><?php print($obj); ?></p></div>
<!-- Fin du Div -->
</body></html>
Mais comme ca malheuresement ca fonctionne toujours pas je dois faire quelques choses de travers obligé ??