0

i try to send the looped echo output via mail like below.

Do i have to transfer the output into an array first?

<?php
$jsonData = file_get_contents("https://test.com");
$data = json_decode($jsonData,true);
foreach ($data["results"] as $value) {

    if($value["fuel"]=="Elektro"){
    echo ($value[product_stock_total]);
    echo "*";

}}
?>

<?php
$to = "test@me.com";
$subject = "This is a test HTML email";

$message = "
<html>
<head>
<title>$total</title>
</head>
<body>
<p>Gesamt: $total</p>
<p>MINI: $totalmini</p>
</body>
</html>
";

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

Thanks in advance :)

  • 1
    Instead of `echo` put the values in a variable. Then include the variable in `$message` somewhere. If `product_stock_total` is an index that should be quoted as well. – user3783243 Apr 16 '21 at 20:30
  • More examples: [!ddso php collect foreach output to variable](https://duckduckgo.com/?q=site%3Astackoverflow.com+php+collect+foreach+output+to+variable&ia=web) – mario Apr 16 '21 at 20:34

0 Answers0