From bebfc4b4e7c3c041b923a95fd063ad731011a47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Gu=C3=A9rard?= Date: Wed, 11 Jan 2012 20:34:37 +0100 Subject: [PATCH] Headers separation fix Fix the header separating character (needs to be \r\n). Merge header creation with sendEmail. --- adminstuds.php | 20 ++++++-------------- contacts.php | 9 +++++---- creation_sondage.php | 6 ++---- fonctions.php | 25 +++++++++---------------- studs.php | 7 ++----- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 45c7c0b..9ee5b9d 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -103,7 +103,6 @@ $dsondage=$sondage->FetchObject(false); //si la valeur du nouveau titre est valide et que le bouton est activé $adresseadmin = $dsondage->mail_admin; -$headers = makeHeaders() ; if (isset($_POST["boutonnouveautitre"]) || isset($_POST["boutonnouveautitre_x"])) { if(issetAndNoEmpty('nouveautitre') === false) { @@ -120,8 +119,7 @@ if (isset($_POST["boutonnouveautitre"]) || isset($_POST["boutonnouveautitre_x"]) _("[ADMINISTRATOR] New title for your poll") . ' ' . NOMAPPLICATION, _("You have changed the title of your poll. \nYou can modify this poll with this link") . " :\n\n".getUrlSondage($numsondageadmin, true)."\n\n" . - _("Thanks for your confidence.") . "\n" . NOMAPPLICATION, - $headers ); + _("Thanks for your confidence.") . "\n" . NOMAPPLICATION ); } } } @@ -143,8 +141,7 @@ if (isset($_POST["boutonnouveauxcommentaires"]) || isset($_POST["boutonnouveauxc _("[ADMINISTRATOR] New comments for your poll") . ' ' . NOMAPPLICATION, _("You have changed the comments of your poll. \nYou can modify this poll with this link") . " :\n\n".getUrlSondage($numsondageadmin, true)." \n\n" . - _("Thanks for your confidence.") . "\n" . NOMAPPLICATION, - $headers ); + _("Thanks for your confidence.") . "\n" . NOMAPPLICATION ); } } } @@ -166,8 +163,7 @@ if (isset($_POST["boutonnouvelleadresse"]) || isset($_POST["boutonnouvelleadress _("[ADMINISTRATOR] New email address for your poll") . ' ' . NOMAPPLICATION, _("You have changed your email address in your poll. \nYou can modify this poll with this link") . " :\n\n".getUrlSondage($numsondageadmin, true)."\n\n" . - _("Thanks for your confidence.") . "\n" . NOMAPPLICATION, - $headers ); + _("Thanks for your confidence.") . "\n" . NOMAPPLICATION ); } } } @@ -327,8 +323,7 @@ if (isset($_POST["confirmesuppression"]) || isset($_POST["confirmesuppression_x" _("[ADMINISTRATOR] Removing of your poll") . ' ' . NOMAPPLICATION, _("You have removed your poll. \nYou can make new polls with this link") . " :\n\n".get_server_name()."index.php \n\n" . - _("Thanks for your confidence.") . "\n" . NOMAPPLICATION, - $headers ); + _("Thanks for your confidence.") . "\n" . NOMAPPLICATION ); //affichage de l'ecran de confirmation de suppression de sondage print_header(); @@ -471,12 +466,10 @@ if (isset($_POST["ajoutercolonne_x"]) && issetAndNoEmpty('nouvellecolonne') && ( $sql = $connect->Prepare($sql); if ($connect->Execute($sql, array($nouveauxsujets, $numsondage))) { //envoi d'un mail pour prévenir l'administrateur du changement - $headers = makeHeaders() ; sendEmail( "$adresseadmin", "" . _("[ADMINISTRATOR] New column for your poll").NOMAPPLICATION, "" . _("You have added a new column in your poll. \nYou can inform the voters of this change with this link") . - " : \n\n".getUrlSondage($numsondage)." \n\n " . _("Thanks for your confidence.") . "\n".NOMAPPLICATION, - $headers ); + " : \n\n".getUrlSondage($numsondage)." \n\n " . _("Thanks for your confidence.") . "\n".NOMAPPLICATION ); } } @@ -590,8 +583,7 @@ if (isset($_POST["ajoutercolonne_x"]) && ($dsondage->format == "D" || $dsondage- sendEmail( $adresseadmin, _("[ADMINISTRATOR] New column for your poll"), _("You have added a new column in your poll. \nYou can inform the voters of this change with this link"). - " : \n\n".getUrlSondage($numsondage)." \n\n " . _("Thanks for your confidence.") . "\n".NOMAPPLICATION, - $headers ); + " : \n\n".getUrlSondage($numsondage)." \n\n " . _("Thanks for your confidence.") . "\n".NOMAPPLICATION ); } else { $erreur_ajout_date="yes"; } diff --git a/contacts.php b/contacts.php index ef6c9a3..d1d72c4 100644 --- a/contacts.php +++ b/contacts.php @@ -52,15 +52,16 @@ if ((isset($_POST['envoiquestion']) || isset($_POST['envoiquestion_x'])) && isse $message=str_replace("\\","",$_POST["question"]); //envoi des mails - $headers = makeHeaders() ; if (isset($_POST['adresse_mail']) && !empty($_POST['adresse_mail']) && validateEmail($_POST['adresse_mail'])) { - $headers .= "\r\n".'Reply-To: '.$_POST['adresse_mail']; + $headers = 'Reply-To: '.$_POST['adresse_mail']; + } else { + $headers = '' ; } + sendEmail( ADRESSEMAILADMIN, "" . _("[CONTACT] You have sent a question ") . "".NOMAPPLICATION, "" . _("You have a question from a user ") . " ".NOMAPPLICATION."\n\n" . _("User") . " : ".$_POST["nom"]."\n\n" . _("User's email address") . " : $_POST[adresse_mail]\n\n" . _("Message") . " :".$message,$headers ); if (isset($_POST['adresse_mail']) && !empty($_POST['adresse_mail']) && validateEmail($_POST['adresse_mail'])) { - $headers = makeHeaders() ; - sendEmail( "$_POST[adresse_mail]", "" . _("[COPY] Someone has sent a question ") . "".NOMAPPLICATION, "" . _("Here is a copy of your question") . " :\n\n".$message." \n\n" . _("We're going to answer your question shortly.") . "\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION,$headers ); + sendEmail( "$_POST[adresse_mail]", "" . _("[COPY] Someone has sent a question ") . "".NOMAPPLICATION, "" . _("Here is a copy of your question") . " :\n\n".$message." \n\n" . _("We're going to answer your question shortly.") . "\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION ); } //affichage de la page de confirmation d'envoi diff --git a/creation_sondage.php b/creation_sondage.php index 648be34..f0e2d40 100644 --- a/creation_sondage.php +++ b/creation_sondage.php @@ -82,8 +82,6 @@ function ajouter_sondage() $date_fin = time()+15552000; } - $headers = makeHeaders() ; - global $connect; $sql = 'INSERT INTO sondage @@ -118,8 +116,8 @@ function ajouter_sondage() $message_admin = sprintf($message_admin, getUrlSondage($sondage_admin, true)); if (validateEmail($_SESSION['adresse'])) { - sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $headers ); - sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $headers ); + sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin ); + sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message ); } $date=date('H:i:s d/m/Y:'); diff --git a/fonctions.php b/fonctions.php index 169a538..89aa52b 100644 --- a/fonctions.php +++ b/fonctions.php @@ -183,28 +183,21 @@ function sendEmail( $to, $subject, $body, $headers, $param) } ; $subject = '=?UTF-8?B?' . base64_encode( html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' ) ) . '?=' ; + + $encoded_app = '=?UTF-8?B?' . base64_encode( NOMAPPLICATION ) . '?=' ; + + if ( $headers ) $headers .= "\r\n" + $headers .= sprintf( "From: %s <%s>\r\n", $encoded_app, ADRESSEMAILADMIN ) + $headers .= "MIME-Version: 1.0\r\n" + $headers .= "Content-Type: text/plain; charset=UTF-8\r\n" + $headers .= "Content-Transfer-Encoding: 8bit" + $body = html_entity_decode( $body, ENT_QUOTES, 'UTF-8' ) ; mail( $to, $subject, $body, $headers, $param ) ; } -function makeHeaders() { - - $headers_str = << -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit -EOF; - - $encoded_app = '=?UTF-8?B?' . base64_encode( NOMAPPLICATION ) . '?=' ; - $headers = sprintf( $headers_str, $encoded_app, ADRESSEMAILADMIN ) ; - - return $headers ; - -} - /** * Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau diff --git a/studs.php b/studs.php index c74052b..fd89460 100644 --- a/studs.php +++ b/studs.php @@ -171,14 +171,12 @@ if (!is_error(NO_POLL) && (isset($_POST["boutonp"]) || isset($_POST["boutonp_x"] $connect->Execute($sql, array($nom, $numsondage, $nouveauchoix)); if ($dsondage->mailsonde || /* compatibility for non boolean DB */ $dsondage->mailsonde=="yes" || $dsondage->mailsonde=="true") { - $headers = makeHeaders() ; sendEmail( "$dsondage->mail_admin", "[".NOMAPPLICATION."] "._("Poll's participation")." : ".html_entity_decode($dsondage->titre, ENT_QUOTES, 'UTF-8')."", html_entity_decode("\"$nom\" ", ENT_QUOTES, 'UTF-8'). _("has filled a line.\nYou can find your poll at the link") . " :\n\n". getUrlSondage($numsondage)." \n\n" . - _("Thanks for your confidence.") . "\n". NOMAPPLICATION, - $headers ); + _("Thanks for your confidence.") . "\n". NOMAPPLICATION ); } } } else { @@ -307,8 +305,7 @@ if ($testmodifier) { $connect->Execute($sql, array($nouveauchoix, $data->nom, $data->id_users)); if ($dsondage->mailsonde=="yes") { - $headers = makeHeaders() ; - sendEmail( "$dsondage->mail_admin", "[".NOMAPPLICATION."] " . _("Poll's participation") . " : ".html_entity_decode($dsondage->titre, ENT_QUOTES, 'UTF-8'), "\"".html_entity_decode($data->nom, ENT_QUOTES, 'UTF-8')."\""."" . _("has filled a line.\nYou can find your poll at the link") . " :\n\n".getUrlSondage($numsondage)." \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION,$headers ); + sendEmail( "$dsondage->mail_admin", "[".NOMAPPLICATION."] " . _("Poll's participation") . " : ".html_entity_decode($dsondage->titre, ENT_QUOTES, 'UTF-8'), "\"".html_entity_decode($data->nom, ENT_QUOTES, 'UTF-8')."\""."" . _("has filled a line.\nYou can find your poll at the link") . " :\n\n".getUrlSondage($numsondage)." \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION ); } }