我使用Zend_View来模板文本电子邮件内容。但是,我遇到了一个我一直无法解决的问题:如果一行以一个php块(?>)结尾,那么换行符会丢失。使用Zend_View丢失换行符的文本电子邮件模板
有没有人有任何想法我可以解决这个问题?
该应用程序使用Zend框架,但我没有特别的理由使用Zend_View来呈现电子邮件模板(除了它看起来是最简单,最明显的方法),所以如果有替代解决方案,好。
我试过检查原始文本输出,并且换行符完全丢失。没有“\ r”或“\ n”可以看到,所以我没有什么可以替代的。
代码发送电子邮件:
$emailView = new Zend_View(); $emailView->setScriptPath(realpath (FRONTEND_APPLICATION_PATH .'/../email/')); $bodyText = $emailView->render('recruitment-job-alert-text.phtml'); // $model = new Model_VacancyDetail(); // $model->find(1); // $emailView->vacancyDetail = $model; $mail = new Zend_Mail(); $mail->setSubject('Job Alert: ' . $model->references['vacancy_type']); $mail->addTo($fromEmail, $fromName); $mail->setFrom($fromEmail, $fromName); $mail->setBodyHtml($bodyHtml); $mail->setBodyText($bodyText); $mail->send();
电子邮件模板内容:
Title: <?= $this->escape($this->vacancyDetail->references['vacancy_type']) ?> Location: <?= $this->vacancyDetail->references['name'] ?> Department: <?= $this->vacancyDetail->references['department_name'] ?> Require Driving Licence: <?= ($this->vacancyDetail->requireDrivingLicence == 1) ? 'Yes' : 'No' ?> Working Hours: <?= $this->vacancyDetail->workingHours ?>. Benefits: <?= $this->vacancyDetail->benefits ?>. Salary: <?= $this->vacancyDetail->salary ?>. Details: <?= strip_tags($this->vacancyDetail->description) ?> Apply now at http://www.example.com/recruitment
导致邮件内容的例子:
Title: Example Vacancy Type Location: Example LocationDepartment: Example DepartmentRequire Driving Licence: YesWorking Hours: 40. Benefits: Company car. Salary: £15,000pa. Details: This is an example position. It does not really exist. Apply now at http://www.example.com/recruitment
电子邮件是否显示换行符或者在PHP脚本查看时是否没有文本?即var_dump($ bodyText);死;那么在脚本中查看源代码,是否仍然存在换行符?如果是这样,那么这是邮件的一部分,否则它是zend_view。 – 2010-08-04 13:18:13
在渲染视图之后,它们并不在视图中,但在它们被放入Zend_Mail之前,所以它看起来像是Zend_View或php本身的问题(还没有看到Zend_View如何渲染文件) – AllenJB 2010-08-04 15:48:27