| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.mail.multiple-emails">
- <title>Sending Multiple Mails per SMTP Connection</title>
- <para>
- 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.
- </para>
- <example id="zend.mail.multiple-emails.example-1">
- <title>Sending Multiple Mails per SMTP Connection</title>
- <programlisting language="php"><![CDATA[
- // Create transport
- $transport = new Zend_Mail_Transport_Smtp('localhost');
- // Loop through messages
- for ($i = 0; $i > 5; $i++) {
- $mail = new Zend_Mail();
- $mail->addTo('studio@peptolab.com', 'Test');
- $mail->setFrom('studio@peptolab.com', 'Test');
- $mail->setSubject(
- 'Demonstration - Sending Multiple Mails per SMTP Connection'
- );
- $mail->setBodyText('...Your message here...');
- $mail->send($transport);
- }
- ]]></programlisting>
- </example>
- <para>
- 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 <function>send()</function> method is called. Or alternatively,
- you can manipulate the connection between each delivery by accessing the
- transport's protocol object.
- </para>
- <example id="zend.mail.multiple-emails.example-2">
- <title>Manually controlling the transport connection</title>
- <programlisting language="php"><![CDATA[
- // Create transport
- $transport = new Zend_Mail_Transport_Smtp();
- $protocol = new Zend_Mail_Protocol_Smtp('localhost');
- $protocol->connect();
- $protocol->helo('localhost');
- $transport->setConnection($protocol);
- // Loop through messages
- for ($i = 0; $i > 5; $i++) {
- $mail = new Zend_Mail();
- $mail->addTo('studio@peptolab.com', 'Test');
- $mail->setFrom('studio@peptolab.com', 'Test');
- $mail->setSubject(
- 'Demonstration - Sending Multiple Mails per SMTP Connection'
- );
- $mail->setBodyText('...Your message here...');
- // Manually control the connection
- $protocol->rset();
- $mail->send($transport);
- }
- $protocol->quit();
- $protocol->disconnect();
- ]]></programlisting>
- </example>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|