begin process at 2012 05 28 22:29:14
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Divers

 > 

Débutant(e)

 > 

Envoyer le contenu d'un panier php par mail


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Envoyer le contenu d'un panier php par mail

vendredi 10 décembre 2010 à 06:46:30 | Envoyer le contenu d'un panier php par mail

odogp1

Bonsoir à tous, avant d'apprendre le php je devrais apprendre le francais... Veuillez m'éscuser pour les fautes !!! je vous présente mon problème : j'ai crée un panier en php qui fonctionne très bien, avec des boutons "ajouter au panier" sur le site... Cela me crée, dans une page, un tableau avec les differents produits désirés. Maintenant je voudrai envoyer le contenu de ce tableau vers un mail. J'ai cherché sur le net, mais je ne comprend pas tout car je suis plus que débutant !!!! Avez vous la solution à mon problème ? Quel code je doit mettre, et surtout ou... Je fait l'assisté

Voici le code de mes pages:

panier.php
<?php
session_start();
include_once("fonctions-panier.php");

$erreur = false;

$action = (isset($_POST['action'])? $_POST['action']: (isset($_GET['action'])? $_GET['action']:null )) ;
if($action !== null)
{
if(!in_array($action,array('ajout', 'suppression', 'refresh')))
$erreur=true;

//récuperation des variables en POST ou GET
$l = (isset($_POST['l'])? $_POST['l']: (isset($_GET['l'])? $_GET['l']:null )) ;
$p = (isset($_POST['p'])? $_POST['p']: (isset($_GET['p'])? $_GET['p']:null )) ;
$q = (isset($_POST['q'])? $_POST['q']: (isset($_GET['q'])? $_GET['q']:null )) ;

//Suppression des espaces verticaux
$l = preg_replace('#\v#', '',$l);
//On verifie que $p soit un float
$p = floatval($p);

//On traite $q qui peut etre un entier simple ou un tableau d'entier

if (is_array($q)){
$QteArticle = array();
$i=0;
foreach ($q as $contenu){
$QteArticle[$i++] = intval($contenu);
}
}
else
$q = intval($q);

}

if (!$erreur){
switch($action){
Case "ajout":
ajouterArticle($l,$q,$p);
break;

Case "suppression":
supprimerArticle($l);
break;

Case "refresh" :
for ($i = 0 ; $i < count($QteArticle) ; $i++)
{
modifierQTeArticle($_SESSION['panier']['libelleProduit'][$i],round($QteArticle[$i]));
}
break;

Default:
break;
}
}

echo '<?xml version="1.0" encoding="utf-8"?>';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<head>
<title>Votre panier</title>
</head>
<body>

<form method="post" action="panier.php">
<table width="729" height="48" align="center" >
<tr>
<td colspan="4" style="font-size:36px; text-align: center;">Votre Devis</td>
</tr>
<tr>
<td colspan="4" align="center" style="font-size:24px"><a href="javascript: void(0);" onclick="window.close()">Retour vers la liste des produits</a></td>
</tr>
<tr>
<td width="387"><strong><u>Produits</u></strong></td>
<td width="41"><strong><u>Qte</u></strong></td>
<td width="132"><strong><u>Prix Unitaire</u></strong></td>
<td width="149"></td>
</tr>


<?php
if (creationPanier())
{
$nbArticles=count($_SESSION['panier']['libelleProduit']);
if ($nbArticles <= 0)
echo "<tr><td>Votre panier est vide </ td></tr>";
else
{
for ($i=0 ;$i < $nbArticles ; $i++)
{
echo "<tr>";
echo "<td> - ".htmlspecialchars($_SESSION['panier']['libelleProduit'][$i])."</ td>";
echo "<td><input type=\"text\" size=\"4\" name=\"q[]\" value=\"".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."\"/></td>";
echo "<td>".htmlspecialchars($_SESSION['panier']['prixProduit'][$i])." euros</td>";
echo "<td><a href=\"".htmlspecialchars("panier.php?action=suppression&l=".rawurlencode($_SESSION['panier']['libelleProduit'][$i]))."\">Retirer du panier</a></td>";
echo "</tr>";
}

echo "<tr><td colspan=\"2\"> </td>";
echo "<td colspan=\"2\">";
echo "Total : ".MontantGlobal();
echo " euros</td></tr>";

echo "<tr><td colspan=\"4\">";
echo "<input type=\"submit\" value=\"Recalculer\"/>";
echo "<input type=\"hidden\" name=\"action\" value=\"refresh\"/>";

echo "</td></tr>";
}
}
?>
</table>
</form>
<br /><div align="center" style="font-size:24px"><a href="javascript: void(0);" onclick="window.close()">Retour vers la liste des produits</a></div><br /><div align="center" style="position:relative; height: 420px; color: #FFF;" > <form name="formulaire" action="formmail.php" method="post" onSubmit="return verification()">

<table width="402">
<tr>
<td width="143">&nbsp;</td>
<td width="258">
Monsieur
<input type="radio" name="sex" value="Monsieur" id="sex">
Madame
<input type="radio" name="sex" value="madame"id="sex">
<tr>
<td width="143">Votre Nom:<span class="red">*</span></td>
<td width="258">
<input name="nom" type="text" size="42" style="background-color:#CCC"></td></tr>
<tr>
<td width="143">Votre prénom:</td>
<td width="258">
<input name="prenom" type="text" size="42" class="writein" style="background-color:#CCC"></td></tr>
<tr>
<td>Votre Email:<span class="red">*</span></td>
<td width="258">
<input name="email" type="text" size="42" class="writein" style="background-color:#CCC"></td></tr>
<tr>
<tr>
<td>Votre code postal:</td>
<td width="258">
<input name="codepostal" type="text" class="writein" size="42" maxlength="5" style="background-color:#CCC"></td></tr>
<tr>
<td>Votre ville:</td>
<td width="258">
<input name="ville" type="text" size="42" class="writein" style="background-color:#CCC"></td></tr>
<tr>
<td>Sujet:</td>
<td width="258">
<input name="sujet" type="text" size="42" class="writein" style="background-color:#CCC"></td></tr>
<tr>
<td colspan=2><p>Votre message:<span class="red">*</span><br>
<textarea name="texte" cols="50" rows="5" class="writein" style="background-color:#CCC"></textarea>
</p></td>
</tr>
</table>
<span class="red">*Champs obligatoire</span><br />
<input type=reset value=Annuler>
- <input type='submit' value=Envoyer>

</form>

</div>
</body>
</html>



formmaildevis.php

<?php

$adresse = "contact@xxxxxx.fr";
$site = "www.xxxxxx.fr";

$TO = $adresse;

$head .= "Content-Type: text/plain; charset=iso-8859-1\n";

$sujet = "Devis";

$tableau = "explode("|",$tableau)";
$res = mail($TO, $sujet, $tableau, $head);

if (true == $res) {
Header("Location: http://".$site."/formmailok.html" );
} else {
Header("Location: http://".$site."/formmailpasok.html" );
}
?>





fonctions-panier.php

<?php

/**
* Verifie si le panier existe, le créé sinon
* @return booleen
*/
function creationPanier(){
if (!isset($_SESSION['panier'])){
$_SESSION['panier']=array();
$_SESSION['panier']['libelleProduit'] = array();
$_SESSION['panier']['qteProduit'] = array();
$_SESSION['panier']['prixProduit'] = array();
$_SESSION['panier']['verrou'] = false;
}
return true;
}


/**
* Ajoute un article dans le panier
* @param string $libelleProduit
* @param int $qteProduit
* @param float $prixProduit
* @return void
*/
function ajouterArticle($libelleProduit,$qteProduit,$prixProduit){

//Si le panier existe
if (creationPanier() && !isVerrouille())
{
//Si le produit existe déjà on ajoute seulement la quantité
$positionProduit = array_search($libelleProduit, $_SESSION['panier']['libelleProduit']);

if ($positionProduit !== false)
{
$_SESSION['panier']['qteProduit'][$positionProduit] += $qteProduit ;
}
else
{
//Sinon on ajoute le produit
array_push( $_SESSION['panier']['libelleProduit'],$libelleProduit);
array_push( $_SESSION['panier']['qteProduit'],$qteProduit);
array_push( $_SESSION['panier']['prixProduit'],$prixProduit);
}
}
else
echo "Un probleme est survenu veuillez contacter l administrateur du site.";
}



/**
* Modifie la quantité d'un article
* @param $libelleProduit
* @param $qteProduit
* @return void
*/
function modifierQTeArticle($libelleProduit,$qteProduit){
//Si le panier éxiste
if (creationPanier() && !isVerrouille())
{
//Si la quantité est positive on modifie sinon on supprime l'article
if ($qteProduit > 0)
{
//Recharche du produit dans le panier
$positionProduit = array_search($libelleProduit, $_SESSION['panier']['libelleProduit']);

if ($positionProduit !== false)
{
$_SESSION['panier']['qteProduit'][$positionProduit] = $qteProduit ;
}
}
else
supprimerArticle($libelleProduit);
}
else
echo "Un probleme est survenu veuillez contacter l administrateur du site.";
}

/**
* Supprime un article du panier
* @param $libelleProduit
* @return unknown_type
*/
function supprimerArticle($libelleProduit){
//Si le panier existe
if (creationPanier() && !isVerrouille())
{
//Nous allons passer par un panier temporaire
$tmp=array();
$tmp['libelleProduit'] = array();
$tmp['qteProduit'] = array();
$tmp['prixProduit'] = array();
$tmp['verrou'] = $_SESSION['panier']['verrou'];

for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++)
{
if ($_SESSION['panier']['libelleProduit'][$i] !== $libelleProduit)
{
array_push( $tmp['libelleProduit'],$_SESSION['panier']['libelleProduit'][$i]);
array_push( $tmp['qteProduit'],$_SESSION['panier']['qteProduit'][$i]);
array_push( $tmp['prixProduit'],$_SESSION['panier']['prixProduit'][$i]);
}

}
//On remplace le panier en session par notre panier temporaire à jour
$_SESSION['panier'] = $tmp;
//On efface notre panier temporaire
unset($tmp);
}
else
echo "Un probleme est survenu veuillez contacter l administrateur du site.";
}


/**
* Montant total du panier
* @return int
*/
function MontantGlobal(){
$total=0;
for($i = 0; $i < count($_SESSION['panier']['libelleProduit']); $i++)
{
$total += $_SESSION['panier']['qteProduit'][$i] * $_SESSION['panier']['prixProduit'][$i];
}
return $total;
}


/**
* Fonction de suppression du panier
* @return void
*/
function supprimePanier(){
unset($_SESSION['panier']);
}

/**
* Permet de savoir si le panier est verrouillé
* @return booleen
*/
function isVerrouille(){
if (isset($_SESSION['panier']) && $_SESSION['panier']['verrou'])
return true;
else
return false;
}

/**
* Compte le nombre d'articles différents dans le panier
* @return int
*/
function compterArticles()
{
if (isset($_SESSION['panier']))
return count($_SESSION['panier']['libelleProduit']);
else
return 0;

}

?>



Désolé pour se message indigeste
vendredi 10 décembre 2010 à 07:37:17 | Re : Envoyer le contenu d'un panier php par mail

odogp1

erreur de ma part, ma page formmaildevis.php est comme cela en fait :

<?php
/* Remplacer votre_adresse@mail.net par votre adresse mail
Remplacer www.votre_domaine.net par votre nom de domaine */

$adresse = "contact@xxx.fr";
$site = "www.xxx.fr";

$TO = $adresse;

$head = "From: ".$adresse."\n";
$head .= "X-Sender: <".$adresse.">\n";
$head .= "X-Mailer: PHP\n";
$head .= "Return-Path: <".$adresse.">\n";
$head .= "Content-Type: text/plain; charset=iso-8859-1\n";

$sujet = "Devis";

$informations = "
Nom: ".$_POST['nom']." \r\n
Prénom: ".$_POST['prenom']." \r\n
Email du formulaire: ".$_POST['email']." \r\n
Code Postal: ".$_POST['codepostal']." \r\n
Ville: ".$_POST['ville']." \r\n
Sujet du formulaire: ".$_POST['title']."\r\n
Message: ".$_POST['texte']." \r\n";
utf8_decode($texte);
$res = mail($TO, $sujet ,$informations, $head);

if (true == $res) {
Header("Location: http://".$site."/formmailok.html" );
} else {
Header("Location: http://".$site."/formmailpasok.html" );
}
?>
vendredi 10 décembre 2010 à 15:12:43 | Re : Envoyer le contenu d'un panier php par mail

cod57

bonjour

dans formmaildevis.php tu as $texte veux tu y mettre le detail de la commande ? un tableau comme dans une facture ?
1 - voir la forme de ton array
2 - faire une boucle pour formater du html

a++

<?php

var_dump($_SESSION['panier']);

echo '<br />';

echo '<pre>';
print_r($_SESSION['panier']);
echo '</pre>';

//puis formater ton tableau pour l'afficher en html

/* Remplacer votre_adresse@mail.net par votre adresse mail
Remplacer www.votre_domaine.net par votre nom de domaine */

/* pour l'instant pas actif test ...
$adresse = "contact@xxx.fr";
$site = "www.xxx.fr";

$TO = $adresse;

$head = "From: ".$adresse."\n";
$head .= "X-Sender: <".$adresse.">\n";
$head .= "X-Mailer: PHP\n";
$head .= "Return-Path: <".$adresse.">\n";
$head .= "Content-Type: text/plain; charset=iso-8859-1\n";

$sujet = "Devis";

$informations = "
Nom: ".$_POST['nom']." \r\n
Prénom: ".$_POST['prenom']." \r\n
Email du formulaire: ".$_POST['email']." \r\n
Code Postal: ".$_POST['codepostal']." \r\n
Ville: ".$_POST['ville']." \r\n
Sujet du formulaire: ".$_POST['title']."\r\n
Message: ".$_POST['texte']." \r\n";
utf8_decode($texte);
$res = mail($TO, $sujet ,$informations, $head);

if (true == $res) {
Header("Location: http://".$site."/formmailok.html" );
} else {
Header("Location: http://".$site."/formmailpasok.html" );
}
*/
?>
vendredi 10 décembre 2010 à 16:11:43 | Re : Envoyer le contenu d'un panier php par mail

odogp1

Merci pour cette réponse rapide, mais je le met ou :

<?php

var_dump($_SESSION['panier']);

echo '<br />';

echo '<pre>';
print_r($_SESSION['panier']);
echo '</pre>';

Désolé chu débutant merci encore
lundi 20 décembre 2010 à 00:24:50 | Re : Envoyer le contenu d'un panier php par mail

odogp1

Petit up !!!
samedi 2 juillet 2011 à 13:50:25 | J'ai trouvé tout seul !!!! après 8 mois

odogp1

Réponse acceptée !
Trop simple en fait:


<input type="hidden" name="tablo" value=" <?php
if (creationPanier())
{
$nbArticles=count($_SESSION['panier']['libelleProduit']);
if ($nbArticles <= 0)
echo "Votre panier est vide ";
else
{
for ($i=0 ;$i < $nbArticles ; $i++)
{

echo "- ".htmlspecialchars($_SESSION['panier']['libelleProduit'][$i])." ";
echo ": Nombre : ".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."\r\n";


}

echo "Total : ".MontantGlobal();
echo " euros";

}
}
?>


puis: Devis: ".$_POST['tablo']." \r\n"; dans le php d'envoi qui récupère la variable de session



Merci




Cette discussion est classée dans : php, session, echo, panier, libelleproduit


Répondre à ce message

Sujets en rapport avec ce message

PB avec les sessions [ par lpikachu58 ] Salut les jeunes, j'ai un pb avec les sessions php. Ca marche mais j'ai warning que je voudrais bien virer. Ma question est comment ne pas avoir de wa SESSIONS AVEC COOKIES [ par vincenteraptor ] Ugh!j ai un petit pb! voila je voudrais utiliser les sessions avec passage de l'id de session dans un cookie.Pour comprendre la chose j ai telechargé espace membre en PHP [ par silendus ] je vais essayé d'être clair :)Donc je suis en train de faire un site en PHP avec gestion de membres.le problème que je rencontre est le suivant: je n' SESSION = Problèmes [ par Developpator ] Hello, j'ai un petit problème avec ma session pour protéger des pages, est-ce que quelqu'un peut m'aide !!!!Première page: celle du login?>Document sa Problème variable SESSION [ par lagombe ] Salut à tous,Voilà j'ai un problème de passage de variable de SESSION... En bref: j'ai une page d'identification avec ident et mot de passe. J'associe session [ par RaygKross ] Salut à tous le plus simple c que je mette d'abord mes 2 fichiersmon fichier identification.phpif(isset($_GET['SID'])){ session_id($_GET['SID']); se Sessions :: problème ram-dam.net [ par Aka_rd ] Bonjour a tous! Je viens de lancer un site web (www.ram-dam.net),mais comme d'habitude, au moment de mettre le tout en ligne, des problèmes apparraiss pb de variable [ par oceane751 ] bonjour a tous!! voila je suis en train de creer une boutique en ligne avec php et une base de donnéesj'utilise easy php 1.7 je rencontre certaines di Probleme de script d'identification (help !) [ par floxone ] Salut à tous,J'ai un problème avec un script utilisant une identification au travers un header.LE PROBLEME : la fenetre de saisie s'ouvre 2 fois ! J'a pb avec les session [ par billy67000 ] Salut, j'ai crée une session // page1.php session_start(); echo 'Bienvenue à la page numéro 1'<sp


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,702 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales