Introduction to Zend Framework

 Learning Zend Framework


 Zend Framework Reference

  •  Zend_Gdata
  •  Zend_Http
  •  Zend_InfoCard
  •  Zend_Json
  •  Zend_Layout
  •  Zend_Ldap
  •  Zend_Loader
  •  Zend_Locale
  •  Zend_Log
  •  Zend_Mail
  •  Zend_Markup
  •  Zend_Measure
  •  Zend_Memory
  •  Zend_Mime
  •  Zend_Navigation
  •  Zend_Oauth
  •  Zend_OpenId
  •  Zend_Paginator
  •  Zend_Pdf
  •  Zend_ProgressBar
  •  Zend_Queue
  •  Zend_Reflection
  •  Zend_Registry
  •  Zend_Rest

  •  Zend_Search_Lucene
  •  Zend_Serializer
  •  Zend_Server
  •  Zend_Service
  •  Zend_Session
  •  Zend_Soap
  •  Zend_Tag
  •  Zend_Test
  •  Zend_Text
  •  Zend_TimeSync
  •  Zend_Tool
  •  Zend_Tool_Framework
  •  Zend_Tool_Project
  •  Zend_Translate
  •  Zend_Uri
  •  Zend_Validate
  •  Zend_Version
  •  Zend_View
  •  Zend_Wildfire
  •  Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Update 2011-11-16 - Revision 24438 - Version ZF 1.11.x

    45.3. Sending Multiple Mails per SMTP Connection

    By default, a single SMTP transport creates a single connection and re-uses it for the lifetime of the script execution. You may send multiple e-mails through this SMTP connection. A RSET command is issued before each delivery to ensure the correct SMTP handshake is followed.

    Optionally, you can also define a default From email address and name, as well as a default reply-to header. This can be done through the static methods setDefaultFrom() and setDefaultReplyTo(). These defaults will be used when you don't specify a From/Reply-to Address or -Name until the defaults are reset (cleared). Resetting the defaults can be done through the use of the clearDefaultFrom() and clearDefaultReplyTo.

    Example 45.4. Sending Multiple Mails per SMTP Connection

    // Create transport
    $config = array('name' => '');
    $transport = new Zend_Mail_Transport_Smtp(''$config);

    // Set From & Reply-To address and name for all emails to send.
    Zend_Mail::setDefaultFrom('''John Doe');
    Zend_Mail::setDefaultReplyTo('','Jane Doe');

    // Loop through messages
    for ($i 0$i 5$i++) {
    $mail = new Zend_Mail();

    'Demonstration - Sending Multiple Mails per SMTP Connection'
    $mail->setBodyText('...Your message here...');

    // Reset defaults

    If you wish to have a separate connection for each mail delivery, you will need to create and destroy your transport before and after each send() method is called. Or alternatively, you can manipulate the connection between each delivery by accessing the transport's protocol object.

    Example 45.5. Manually controlling the transport connection

    // Create transport
    $transport = new Zend_Mail_Transport_Smtp();

    $protocol = new Zend_Mail_Protocol_Smtp('');


    // Loop through messages
    for ($i 0$i 5$i++) {
    $mail = new Zend_Mail();
    'Demonstration - Sending Multiple Mails per SMTP Connection'
    $mail->setBodyText('...Your message here...');

    // Manually control the connection


    digg delicious meneame google twitter technorati facebook