使用 foreach() 循环和在此循环内使用 ob_start() 和 ob_get_clean() 循环时遇到问题。
这是我的功能:
protected function renderEmail() {
$template = $this->_case.".php";
if(is_file($this->_dir.DS.$template)) {
ob_start();
if(!empty($this->_records)) {
foreach($this->_records as $key => $value) {
${$key} = $value;
}
}
require_once($this->_dir.DS.$template);
return ob_get_clean();
} else {
$this->_errors[] = "Email template not found";
return false;
} }
这个函数基本上是生成电子邮件的内容,然后返回它。
我遇到的问题是,当我遍历多个电子邮件地址时 - 发送相同的电子邮件内容 - 只有第一个返回内容 - 以下是空白 - 知道为什么吗?