Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 980509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:23:35+00:00 2026-05-16T04:23:35+00:00

I’m using Zend_View to template text email content. However, I’ve come across one problem

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:23:36+00:00Added an answer on May 16, 2026 at 4:23 am

    I believe it’s PHP eating the newline after the ?>. Generally this is a good thing, but I can see why it is annoying in your case.

    You’ll probably need to do something like this:

    Title: <?= $this->escape($this->vacancyDetail->references['vacancy_type'])."\n" ?>
    
    Location: <?= $this->vacancyDetail->references['name']."\n" ?>
    Department: <?= $this->vacancyDetail->references['department_name']."\n" ?>
    

    Edit:

    Here’s a reference just to confirm I’m not going crazy: http://www.php.net/manual/en/faq.using.php#faq.using.newlines

    Why is this a good thing? Well imagine your email template was:

    Title: <?= $this->escape($this->vacancyDetail->references['vacancy_type'])."\n" ?>
    
    <?php if (!empty($this->vacancyDetail->references['name'])) { ?>
    Location: <?= $this->vacancyDetail->references['name']."\n" ?>
    <?php } ?>
    Departments:
    <?php foreach ($this->vacancyDetail->references['departments'] as $dept) { ?>
    <?=$dept->name."\n"?>
    <?php } ?>
    

    in that situation you wouldn’t want to end up with several newlines between each of the lines that’s actually output (a problem I had recently in an email template for a non-PHP project).

    Another option for you might be to not store your templates in PHP, just use {name}, {department_name} or similar for your variables and then parse them out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.