IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Récupérer les éléments d'un panier et les mettre dans un mail


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 46
    Points : 21
    Points
    21
    Par défaut Récupérer les éléments d'un panier et les mettre dans un mail
    Bonjour
    j'aimerais savoir s'il est possible de récupérer les éléments d'un panier pour les mettre dans un mail. (dans le cas d'une commande)

    Voila mon panier:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    <?php
    session_start();
    include_once("fonctions-panier.php");
     
    if (isset($_GET['action']))
    {
    	if(in_array( $_GET['action'],array('ajout', 'suppression')))
    	{	
    		$au=preg_replace('#\v#', '',$_GET['au']);
    		$t=preg_replace('#\v#', '',$_GET['t']);
    		$p=floatval($_GET['p']);
    		$an=intval($_GET['an']);
    		$action = $_GET['action'];
    	}
    	switch($action)
    	{
    		Case "ajout":
    		ajouterArticle($au,$t,$p,$an);
    		break;
     
    		Case "suppression":
    		supprimerArticle($t);
    		break;
     
    		Default:
    		break;
     
    	}
    }
     
    echo '<?xml version="1.0" encoding="iso-8859-1"?>';?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> 
    <head>
    <title>Votre panier</title>
    </head>
    <body>
     
        <table border="0" width="1000" height="827" cellspacing="1" cellpadding="2"><tr height="60">
    	<td width="195" align="center" valign="top" height="258">
    			<img border="0" src="images/Logo.JPG" width="194" height="313">
    	</td>
    	<td align="center" width="556" valign="top" height="258">
            <p style="margin-top: 75; margin-left: 170 "><img border="0" src="images/Titre.JPG" width="434" height="74"></p>
            <p align="center" style="margin-left: 200; margin-top: 0;
     margin-bottom: 0"><b><font size="5">17 Rue Clément Marot</font></b></p>
            <p align="center" style="margin-left: 200; margin-top: 0;
     margin-bottom: 0"><b><font size="5">46000 Cahors</font></b></p>
            <p align="center" style="margin-left: 200; margin-top: 0;
     margin-bottom: 0"><b><font size="5">Tél :05.65.35.51.94</font></b></p>
            <p align="center" style="margin-left: 200; margin-top: 0;
     margin-bottom: 0"><b><font size="5">Fax :05.65.35.41.81</font></b></p>
        </td>
    	<td align="center" width="112" valign="top" height="258">
        	<b>&quotphoto de la boutique&quot;</b>
    	</td>
    	</tr>
    	<tr height="100%"><td valign="top">
    			<table cellspacing="0" cellpadding="0" width="145" valign="top">
    				<tr>
    					<td background="./img/up-left2.gif" width="15" 
    height="15"></td><td background="./img/up2.gif" width="115" height="15">
    </td><td background="./img/up-right2.gif" width="15" height="15"></td>
    				</tr>
    				<tr>
    					<td background="./img/left2.gif" width="15" 
    height="15"></td><td background="./img/backdot2.gif" width="115" 
    height="15" align="center"><div id="title"><b>Menu</b></div></td><td 
    background="./img/right2.gif" width="15" height="15"></td>
    				</tr>
    				<tr>
    					<td background="./img/middle-left.gif" 
    width="15" height="15"></td><td background="./img/middle.gif" width="115" 
    height="15"></td><td background="./img/middle-right.gif" width="15" 
    height="15"></td>
    				</tr>
    				<tr>
    					<td background="./img/left3.gif" width="15" 
    height="20"></td><td background="./img/backdot2.gif" width="115" 
    height="20" align="center"><div id="leftmenu"><a 
    href="index.html">Accueil</a></div></td><td background="./img/right3.gif" 
    width="15" height="20"></td>
     
    				</tr>
    				<tr>
    					<td background="./img/left3.gif" width="15" 
    height="20"></td><td background="./img/backdot2.gif" width="115" 
    height="20" align="center"><div id="leftmenu"> <a 
    href="catalogue.html">Catalogue</a> </div></td><td background="./img
    /right3.gif" width="15" height="20"></td>
    				</tr>
    				<tr>
    					<td background="./img/left3.gif" width="15" 
    height="20"></td><td background="./img/backdot2.gif" width="115" 
    height="20" align="center"><div id="leftmenu"> <a href="Condition générale 
    de vente.html">Condition g&eacute;n&eacute;rale de vente</a> </div>
    </td><td background="./img/right3.gif" width="15" height="20"></td>
     
    				</tr>
    				<tr>
    					<td background="./img/left3.gif" width="15" 
    height="20"></td><td background="./img/backdot2.gif" width="115" 
    height="20" align="center"><div id="leftmenu"> <a 
    href="panieroriginal.php">Votre panier</a> </div></td><td background="./img
    /right3.gif" width="15" height="20"></td>
     
    				</tr>
    				<tr>
    					<td background="./img/left3.gif" width="15" 
    height="20"></td><td background="./img/backdot2.gif" width="115" 
    height="20" align="center"><div id="leftmenu"> </div></td><td 
    background="./img/right3.gif" width="15" height="20"></td>
     
    				</tr>
     
    				<tr>
    					<td background="./img/down-left3.gif" 
    width="15" height="11"></td><td background="./img/down3.gif" width="115" 
    height="11"></td><td background="./img/down-right3.gif" width="15" 
    height="11"></td>
    				</tr>
    			</table>
    		</tr>
     
    <td width="100%" valign="top">
    <form method="get" action="panieroriginal.php">
    <table >
    <tr>
          <td colspan="4">Votre panier</td >
    </tr>
    <tr>
          <td width="550">Auteur</td>
          <td width="550">Titre</td>
    	  <td width="550">Prix</td>
          <td width="550">Année</td>
          <td width="550">Action</td>
    </tr>
     
     
    <?php
    if (creationPanier())
    {
    	$nbArticles=count($_SESSION['panier']['Titre']);
    	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']['Nom_auteur'][$i])."</td>";
    			echo "<td>".htmlspecialchars($_SESSION['panier']['Titre'][$i])."</td>";
    			echo "<td>".htmlspecialchars($_SESSION['panier']['Prix_vente_euro'][$i])." €</td>";
    			echo "<td>".htmlspecialchars($_SESSION['panier']['Annee'][$i])."</td>";
    			echo "<td><a href=\"".htmlspecialchars("panieroriginal.php?action=suppression&t=".rawurlencode($_SESSION['panier']['Titre'][$i]))."\">Supprimer l'article<a></td>";
    			echo "</tr>";
    		}  
    		echo "<tr>";
    		echo "<td width='1500'>";
    		echo "Total à payer (hors frais de port) : ".MontantGlobal(); 
    		echo"€";
    		echo "</td></tr>";
    	}
    }
    ?>
    </form>
    </td>
    <table width="150" valign="top" align="center">
    <td>
     
    <a href="Catalogue.html">Effectuer une nouvelle recherche.</a>
     
    <form method="post" action="mail.php" enctype="multipart/form-data">
     
    <p class="titre">Informations personnelles</p>
    <fieldset id="coordonnees">
      <b>Nom : </b>
        <input type=text name="nom" size="30" /></br>
      <b>Prénom : </b>
        <input type=text name="prénom" size="30" /></br>
      <b>Adresse : </b>
        <input type=text name="adresse" size="30" /></br>
      <b>Code postal : </b>
        <input type=text name="codepostal" size="30" /></br>
      <b>Ville : </b>
        <input type=text name="ville" size="30" /></br>
      <b>E-mail : </b>
        <input type=text name="mail" size="30" /></br>
      <b>Téléphone : </b>
        <input type=text name="tel" size="30" /></br>
      <b>Mode de paiement :</b>
    	<select id="paiement" name="paiement">
    	<option value="CB" selected="selected">CB</option>
    	<option value="Chèque">Chèque</option>
    	<option value="Liquide">Liquide</option>
    	</select>
     
    </fieldset>
     
    <p id="buttons">
      <input type="submit" value="Envoyer" name="envoye" />
      <input type="reset" value="Recommencer" />
    </p>
    </table>
    </form>
    </td> 
     
    </table>
    </body>
    </html>
    et voila le code pour envoyer le mail:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    <?php
     
    	include("header.html");
     
    	/* Si le formulaire est envoyé alors on fait les traitements */
    	if (isset($_POST['envoye']))
    	{
    		/* Récupération des valeurs des champs du formulaire */
    		if (get_magic_quotes_gpc())
    		{
    			$nom = stripslashes(trim($_POST['nom']));
    			$prénom = stripslashes(trim($_POST['prénom']));
    			$adresse = stripslashes(trim($_POST['adresse']));
    			$codepostal = stripslashes(trim($_POST['codepostal']));
    			$ville = stripslashes(trim($_POST['ville']));
    			$mail = stripslashes(trim($_POST['mail']));
    			$tel = stripslashes(trim($_POST['tel']));
    			$paiement = stripslashes(trim($_POST['paiement']));
    		}
    		else
    		{
    			$nom = stripslashes(trim($_POST['nom']));
    			$prénom = stripslashes(trim($_POST['prénom']));
    			$adresse = stripslashes(trim($_POST['adresse']));
    			$codepostal = stripslashes(trim($_POST['codepostal']));
    			$ville = stripslashes(trim($_POST['ville']));
    			$mail = stripslashes(trim($_POST['mail']));
    			$tel = stripslashes(trim($_POST['tel']));
    			$paiement = stripslashes(trim($_POST['paiement']));
    		}
    		/* Expression régulière permettant de vérifier si le
    		* format d'une adresse e-mail est correct */
    		$regex_mail = '/^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$/i';
    		/* Expression régulière permettant de vérifier qu'aucun
    		* en-tête n'est inséré dans nos champs */
    		$regex_head = '/[\n\r]/';
    		/* On vérifie que tous les champs sont remplis */
    		if ((empty($nom)) || (empty($prénom)) || (empty($adresse)) || (empty($codepostal)) || (empty($ville)) || (empty($mail)) || (empty($tel)) ) 
    		{
    			$alert = 'Tous les champs doivent être renseignés';
    		}			
    		if (!empty($alert))
    		{
    			echo '<p style="color:red">'.$alert.'</p>';
    		}
    		else
    		{
    			/* On vérifie que le format de l'e-mail est correct */
    			if (!preg_match($regex_mail, $mail))
    			{
    				$alert = 'L\'adresse e-mail '.$mail.' n\'est pas valide';
    			}
    			/* On vérifie qu'il n'y a aucun header dans les champs */
    			elseif (preg_match($regex_head, $mail) || preg_match($regex_head, $nom))
    			{
    				$alert = 'En-têtes interdites dans les champs du formulaire';
    			}
    			if (!empty($alert))
    			{
    				echo '<p style="color:red">'.$alert.'</p>';
    			}
     
    		/* Si aucun problème et aucun cookie créé, on construit le message et on envoie l'e-mail */
    		elseif (!isset($_COOKIE['sent']))
    		{
    			/* Destinataire (votre adresse e-mail) */
    			$to = 'ratich_1@hotmail.com' ;
    			/* Construction du message */
    			$msg = 'Bonjour,'."\r\n\r\n";
    			$msg .= 'Ce mail a été envoyé depuis le site de la librairie ancienne Charbonneau par '.$nom.' '.$prénom."\r\n\r\n";
    			$msg .= 'Voici la commande et les coordonnées :'."\r\n";
    			$msg .= '***************************'."\r\n";
    			$msg .= '<b>Commande :</b>'."\r\n";
    			$msg .= '***************************'."\r\n";
    			$msg .= 'Adresse :'.$adresse."\r\n";
    			$msg .= 'Code Postal :'.$codepostal."\r\n";
    			$msg .= 'Ville :'.$ville."\r\n";
    			$msg .= 'E-mail :'.$mail."\r\n";
    			$msg .= 'Téléphone :'.$tel."\r\n";
    			$msg .= 'Mode de paiement :'.$paiement."\r\n";
    			$msg .= '***************************'."\r\n";
    			/* En-têtes de l'e-mail */
    			$headers = 'From: '.$nom.' <'.$mail.'>'."\r\n\r\n";
    			echo"'.$headers.'";
    			echo"'.$msg.'";
    			/* Envoi de l'e-mail */
    			if (mail($to, $msg, $headers))
    			{
    				$alert = 'E-mail envoyé avec succès';
    				/* On créé un cookie de courte durée (ici 120 secondes) pour éviter de
    				* renvoyer un mail en rafraichissant la page */
    				setcookie("sent", "1", time() + 120);
    				/* On détruit la variable $_POST */
    				unset($_POST);
    			}
    			else
    			{
    				$alert = 'Erreur d\'envoi de l\'e-mail';
    			}
    			if (!empty($alert))
    			{
    				echo '<p style="color:red">'.$alert.'</p>';
    			}
    		}
    		/* Cas où le cookie est créé et que la page est rafraichie, on détruit la variable $_POST */
    		else
    		{
    			unset($_POST);
    		}
    		}
    	}
     
    include("footer.html");
     
    ?>
    Merci d'avance.

  2. #2
    Rédacteur
    Avatar de RideKick
    Homme Profil pro
    Directeur technique
    Inscrit en
    Septembre 2006
    Messages
    5 914
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2006
    Messages : 5 914
    Points : 12 572
    Points
    12 572
    Par défaut
    TU parcours ton panier et tu mets les articles dans une variable que tu affectera quelque part dans ton mail :

    du style :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    $contenu ="<table><tr><td>Quantit&eacute;</td><td>D&eacute;signation</td><td>Prix</td></tr>";
    for ($i=0 ;$i < $nbArticles ; $i++)
       {
        $contenu.= "<tr>";
        $contenu.= "<td>".htmlspecialchars($_SESSION['panier']['qteProduit'][$i])."</td>";
        $contenu.= "<td>".htmlspecialchars($_SESSION['panier']['libelleProduit'][$i])."</ td>";
        $contenu.= "<td>".htmlspecialchars($_SESSION['panier']['prixProduit'][$i])."</td>";
        $contenu.= "</tr>";
       }
    $contenu.= "</table>";
    et dans ton mail tu ajoute

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $msg .= "Votre commande<br />";
    $msg .= $contenu;
    A adapter évidement

    Au passage évite les noms de variable avec des caractères spéciaux ! ($prénom)

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 46
    Points : 21
    Points
    21
    Par défaut
    Ok merci pour ton aide, mais j'ai trouvé une solution tout seul.
    Voila ce que je fais:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <b>Contenu de la commande:</b>
    	<textarea name="commande" rows="10" cols="90" 
    <?php
    if (creationPanier())
    {
    	echo "<td>";
    	$nbArticles=count($_SESSION['panier']['Titre']);
    	if ($nbArticles <= 0)
    	{
    		echo "Votre panier est vide.";
    	}
    	else
    	{
    		for ($i=0 ;$i < $nbArticles ; $i++)
    		{
    			echo "Auteur: ".htmlspecialchars($_SESSION['panier']['Nom_auteur'][$i]).",",
    			 " Titre: ".htmlspecialchars($_SESSION['panier']['Titre'][$i]).",",
    			 " Prix: ".htmlspecialchars($_SESSION['panier']['Prix_vente_euro'][$i])." €,",
    			 " Année: ".htmlspecialchars($_SESSION['panier']['Annee'][$i]).".</br>";
    		}  
    		echo "Total à payer (hors frais de port) : ".MontantGlobal(); 
    		echo"€";
    	}
    }
    ?>
    	</textarea>
    et merci de m'avoir fait la remarque pour prénom.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 11
    Dernier message: 21/11/2014, 18h50
  2. [RegEx] récupérer un élément de la chaine et l'intégrer dans une autre
    Par cedrick21 dans le forum Langage
    Réponses: 2
    Dernier message: 11/01/2013, 16h28
  3. recupérer les éléments d'une collection et les afficher séparement
    Par ramanov dans le forum Collection et Stream
    Réponses: 2
    Dernier message: 03/04/2008, 22h10
  4. Réponses: 1
    Dernier message: 18/12/2006, 10h20
  5. Réponses: 4
    Dernier message: 09/08/2006, 11h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo