I'm using Zend_View to template text email content. However, I've come across one problem which I have been unable to solve: If a line ends with a php block (?>), then the line break is lost.
Does anyone have any idea how I can solve this?
The application is using Zend framework, but I have no particular reason to use Zend_View to render the email template (except that it looked the easiest, most obvious way to do it), so if there's an alternative solution, that would be good.
I've tried examining the raw text output, and the linebreaks are completely lost. No "\r" or "\n" to be seen, so there's nothing left that I can replace.
Code to send email:
$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();
Email template content:
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
Example of resulting email content:
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