从阵列获取数据,并结合使用PHP发送电子邮件 [英] Grab data from array and combine to send email using PHP
本文介绍了从阵列获取数据,并结合使用PHP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的code是:
$itemArray = array();
foreach ($a->getDetails() as $b) {
if ($b->getValue1() !== $b->getValue2()) {
if (!array_key_exists($b->getId(), $itemArray)) {
$itemArray[$b->getId()] = array('name' => $b->getName(), 'age' => $b->getAge());
}
}
}
if (count($itemArray) > 0 && $b->getValue1() !== $b->getValue2()) {
foreach($itemArray as $item) {
$personName = $item['name'];
$personAge = $item['age'] ;
$content = ('Name is: ' . $personName . ', age is: ' . $personAge);
}
}
$emailAddress = 'emailaddress@gmail.com';
$fromEmail = 'noreply@gmail.com';
$body = <<<EOF
Here is an example email:
$content
EOF;
$mail = new sfMail();
$mail->setBody($body);
$mail->send();
现在的邮件只能输出一个条目,如:
Right now the mail only outputs a single entry such as:
Name is: Bob, age is: 20.
但我想的电子邮件输出数组中的所有条目时 $ B-&GT; getValue1()== $ B-&GT;!getValue2()
这样的:
Name is: Bob, age is 20:
Name is: John, age is 30.
如何设置我的内容变量,以便它抓住一切从数组并输出很好地在电子邮件?
How do I set up my content variable so that it grabs everything from the array and outputs it nicely in the email?
谢谢!
推荐答案
只是追加到的 $内容:)
$content = '';
if (count($itemArray) > 0 && $b->getValue1() !== $b->getValue2()) {
foreach($itemArray as $item) {
$personName = $item['name'];
$personAge = $item['age'] ;
$content .= ('Name is: ' . $personName . ', age is: ' . $personAge) . "\n";
}
}
// ... mail setting ...
$body = $content;
这篇关于从阵列获取数据,并结合使用PHP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文