sfZendMailPlugin - 0.0.7

Benjamin Runnels

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
This plugin is deprecated and is not maintained anymore.
Show source


Plugin based on swToolboxPlugin mail feature by Thomas Rabaix. The primary changes from his implementation are seperating the mail feature from swToolbox.

The built in mail feature was removed from sf1.1 and sf1.2. This will simulate the sendEmail method from sf1.0 and add extras features :

  • email decorator
  • Zend_Mail Support
  • Charset and Encoding
  • variables assignement from the controller

This solution is based on Zend_Mail for more information please refer to the Zend Framework documentation available here

Install Zend Framework via pear or manually


  • Install the plugin

    symfony plugin:install sfZendMailPlugin
  • Install Zend Framework manually from Zend's Website or via pear

    pear channel-discover pear.zfcampus.org
    pear install zfcampus/zf
  • Edit the app.yml file

        #framework_location:                         /usr/local/zend/share/ZendFramework/library/Zend
          charset: utf-8                             # charset to use : utf-8, iso-8859-1, ...
          encoding: quoted-printable                 # 7bit, 8bit, quoted-printable, base64 (default : quoted-printable)
          #transport:                                # define which transport class to used, one or the other not both
            # sample with Sendmail
            #class: Zend_Mail_Transport_Sendmail     # Zend_Mail_Transport_Sendmail | Zend_Mail_Transport_Smtp
            #parameters: "-ffrom@yourdomain.com"
            # sample with Smtp
            #class: Zend_Mail_Transport_Smtp         # Zend_Mail_Transport_Sendmail | Zend_Mail_Transport_Smtp
            #  -                           # URL or IP of the smtp server
            #  - { auth: Plain|Crammd5|Login, username: yourusername, password: yourpassword }  #if required, else don't set
          decorator:                                 # define the layout use in the mail
            enabled: off                             # on | off : set true if all your mail share the same layout
            directory: "%SF_APP_TEMPLATE_DIR%"       # where the layout is located, ie %SF_APP_TEMPLATE_DIR%
            template: email                          # name of the layout, automatically translate to name.FORMAT.php
          view:                                      # define the view class used to render the template
            class: sfZendMailView
  • Clear your cache


public function executeConfirmPayment()
  // [...]

  // create object in your controller
  $invoice = Doctrine::getTable('Invoice')->find(..);

  // call the email action
  $this->sendEmail('yourModule', 'sendInvoice', array('invoice' => $invoice);

public function executeSendInvoice(sfWebRequest $request)
  $mail = new sfZendMail;

  $mail->setSubject('Your Invoice #'.$invoice->getReference());
  $mail->setFrom('billing@yoursite.com', 'Billing Service');
  $mail->addTo($this->invoice->getEmail(), $this->invoice->getName());

  $this->mail = $mail;

You should have a least one template file : sendInvoiceSuccess.txt.php or sendInvoiceSuccess.html.php in your module/templates folder.

If you want a specific layout around your email (like default header and footer), enable the decorator option and create a 'email.txt.php' and/or 'email.html.php' inside the decorator directory.