Domanda

Nella mia pagina PHP, sto estraendo un sacco di variabili dall'URL e formattando la loro uscita in una bella tabella HTML. Una sezione nella tabella deve essere creata dinamicamente, dipendente da ciò che è stato ordinato nella pagina web precedente. Infine, sto usando la funzione $ mail per inviare la tabella HTML con tutte le informazioni a un destinatario di posta elettronica.

Il tavolo funziona alla grande, ad eccezione della sezione dinamica con il ciclo while. Il compilatore si sta confondendo perché la mia sintassi è sbagliata. Sospetto che questo sia perché il mio codice è all'interno della variabile $ Message '...'. Qualche consiglio?

<?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);

?>

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top