phparraysstringemailprocesswire

Make a list form php string


I have this code that write inside the variable $products a string of products name:

$products = '';
foreach($order->pad_products as $product) $products .= " $product->title";

When I print $products inside a HTML email body and send the email with PHP, in this case, I sand $msg, I see the name of the products all in one line.

$msg = "
  <html>
    <head>
      <style type='text/css'></style>
    </head>
    <body>
      <h1>Sent!</h1>
      <p>$name thank you</p>
        $products
    </body>
  </html>";

How can I make a list of these products? and, can I delete one of these?


Solution

  • To display them as a list, you simply have to create a list using HTML:

    <?php
    echo "<ul>";
    foreach($order->pad_products as $product) {
        echo "<li>" . $product->title . "</li>";
    }
    echo "</ul>";
    ?>
    

    Alternative, applying to your current code

    <?php
    $products = "";
    foreach($order->pad_products as $product) {
        $products .= "<li>".$product->title."</li>";
    }
    $msg = "
    <html>
    <body>
      <h1>Sent!</h1>
        $products
    </body>
    </html>";