Question

Dans ma page PHP, j'extrait un tas de variables de l'URL et je formate leur sortie dans une belle table HTML. Une section du tableau doit être créée dynamiquement, en fonction de ce qui a été ordonné sur la page Web précédente. Enfin, j'utilise la fonction $ Mail pour envoyer la table HTML avec toutes les informations à un destinataire par e-mail.

La table fonctionne très bien, à l'exception de la section dynamique avec la boucle while. Le compilateur est confus car ma syntaxe est erronée. Je soupçonne que c'est parce que mon code est à l'intérieur de la variable $ message '...'. Aucun conseil?

<?php
// Extracting the variables from URL
$params = $_SERVER['QUERY_STRING'];

// Placing the variables into $array
$array=array();
parse_str($params,$array);

// Identifying the length of the main array and creating an array of KEYS
$keys = array_keys($array);
$keysCount = count($keys);

// And creating an array of corresponding values
$values = array_values($array);

$to = "steve@dutchlandfrozenfoods.com";
$subject = "NEW EUROCLASSIC ORDER";
$message = '
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EuroClassic Fine Family of Pastries - Ordering</title>
</HEAD>
<BODY bgcolor="#F0EFEE">
<table id="hor-minimalist-b" summary="Customer Information">
<thead>
    <tr>
        <th scope="col">Customer Contact:</th>
        <th scope="col">Shipping To:</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>' . $values[0] . '</td>
        <td>' . $values[1] . '</td>
    </tr>
    <tr>
        <td>' . $values[2] . '</td>
        <td>' . $values[3] . '</td>
    </tr>
    <tr>
        <td>' . $values[4] . '</td>
        <td>' . $values[5] . '</td>
    </tr>
    <tr>
        <td></td>
        <td>' . $values[6] . '</td>
    </tr>
</tbody>
</table>

<table id="hor-minimalist-b" summary="Order Details">
<thead>
    <tr>
        <th scope="col">Product:</th>
        <th scope="col">Item Code:</th>
        <th scope="col">Quantity:</th>
        <th scope="col">Ext Price:</th>
    </tr>
</thead>
<tbody>
while ($i = 13; $i < $keysCount-3; $i = $i+2;) 
{
    <tr>
    <td>' . $values[$i] . '</td>
    $i = $i+1;
    <td>' . $values[$i] . '</td>
    $i = $i+1;
    <td>' . $values[$i] . '</td>
    $i = $i+1;
    <td>' . $values[$i] . '</td>
    </tr>
}   
</tbody>
</table>

</BODY>
</HTML>
';

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To:Steve <steve@dutchlandfrozenfoods.com>\r\n";

mail($to, $subject, $message, $headers);

?>

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top