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 549683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:12:34+00:00 2026-05-13T11:12:34+00:00

With Zend_Framework, I wondered what is considered best practice for building up the content

  • 0

With Zend_Framework, I wondered what is considered best practice for building up the content to send in a HTML email. In my case the content of the email that is sent is determined by a number of factors, for example the number of returned rows for a specific value in the database. Because of this it makes sense for me that the content is built up within the controller that sends the email which talks to the relevant database models and determines what the content should be. Where i’m not sure this works is that our designers and copyrighters will often want to adjust the copy in emails and this would then require them to make changes to a model or ask me to. Should i be handling this differently? Should i perhaps be storing HTML snippets somewhere containing the different text and then calling these somehow?

EDIT following from the answer by fireeyedboy, would it be acceptable to do something like this. Create a folder inside views called “partials” and use this to store text/html snippets that i can then call in where i need and replace special strings with dynamic values using regexp(or similar).

$nview = new Zend_View();
$nview->setScriptPath(APPLICATION_PATH.'/views/partials/');
$bodytext = $nview->render('response.phtml');
$mail = new Zend_Mail();
$mail->setBodyText($bodytext);
// etc ...

e.g. in this context where two different templates could be used depending on variables returned from a Model:

// within a controller
public function emailAction()
{
    $images = new Model_ApplicationImages();
    $totimages = count($images->fetchImages($wsid));
    $acceptedImages = $images->fetchImages($wsid,'approved');
    $accepted = count($acceptedImages);
    $rejectedImages = $images->fetchImages($wsid,'rejected');
    $rejected = count($rejectedImages);
    $response = ($rejected == $totimages)?'rejected':'approved';
    $nview = new Zend_View();
    $nview->setScriptPath(APPLICATION_PATH.'/views/partials/');
    $content = $nview->render($response.'.phtml');
    $mail = new Zend_Mail();
    $mail->setBodyText($content);
    // etc
}

Is there a more elegant way i can/should be doing this?

  • 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-13T11:12:35+00:00Added an answer on May 13, 2026 at 11:12 am

    Not sure if this is best practice, but what I did is extend Zend_Mail with methods like these:

    setTemplatePath( $templatePath );
    setTemplateHtml( $templateHtml );
    setTemplateText( $templateText );
    setTemplateArguments( array $templateArguments );
    

    …then at some point in my overwrittensend() I do:

    $view = new Zend_View();
    $view->setScriptPath( $this->_templatePath );
    
    foreach( $this->_templateArguments as $key => $value )
    {
        $view->assign( $key, $value );
    }
    
    if( null !== $this->_templateText )
    {
        $bodyText = $view->render( $this->_templateText );
        $this->setBodyText( $bodyText );
    }
    
    if( null !== $this->_templateHtml )
    {
        $bodyHtml = $view->render( $this->_templateHtml );
        $this->setBodyHtml( $bodyHtml );
    }
    

    So to utilize this you would do something like:

    $mail = new My_Extended_Zend_Mail();
    $mail->setTemplatePath( 'path/to/your/mail/templates' );
    $mail->setTemplateHtml( 'mail.html.phtml' );
    $mail->setTemplateText( 'mail.text.phtml' );
    $mail->setTemplateArguments(
        'someModel' => $someFunkyModel,
        /* etc, you get the point */
    )
    $mail->send();
    

    In other words, with this you can let your designers and copywriters simply edit views (templates) like they are used to already. Hope this helps and has inspired you to come up with something funky that suits your needs.

    PS:
    Since you mention arbitrary data rows, you can, for instance, utilize the partialLoop view helper that comes with ZF for this. But you probably were aware of this already?

    PPS:
    I actually agree with chelmertz’ comment about not extending Zend_Mail but wrapping it in my own component.

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

Sidebar

Related Questions

The zend framework provides a php wrapper for the amazon S3 api that simplifies
In the Zend Framework Quickstart , there has been a change from models that
I need a Zend Framework start up guide PDF file. http://www.mikaelkael.fr/Zend-Framework-1-8-x-documentation.html this is an
In Zend Framework, I have a common use case where I need to propagate
in Zend Framework, whats the best way or recommended way to show or hide
in zend framework, i usually setup vhosts so that i can refer to my
I was wondered is any one was integrating the DataTabes jquery plugin with Zend
Zend Framework: I have the following url /base/url/[number]/[string] OR /base/url/action/controller/param/value I want in the
Zend framework: what is the significance of controller filenames that have init in them?
I use Zend framework with doctrine for a project , the problem is that

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.