我有一个对象,我想插入到我的setBody中。
对象:
{
"v1":
{"name":"n1","price":10},
"v2":
{"name":"n2","price":20}
}
我想要的是什么:
<p>name: n1, price: 10</p>
<p>name: n2, price: 20</p>
我的代码(不正确):
$message->setBody(
'...' .
foreach (products as $key => $value) {
<p>name: $value->name, price: $value->price</p>
}
.'...', 'text/html');
答案 0 :(得分:1)
不确定这是你所要求的,但这是正确的语法:
$myText = "";
foreach (products as $key => $value) {
$myText .= "<p>name:".$value->name.", price:".$value->price."</p>";
}
$message->setBody(
'...'.$myText.'...',
'text/html');