Zend_Mail-MultipleEmails.xml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.mail.multiple-emails">
  4. <title>Sending Multiple Mails per SMTP Connection</title>
  5. <para>
  6. By default, a single SMTP transport creates a single connection and
  7. re-uses it for the lifetime of the script execution. You may send multiple
  8. e-mails through this SMTP connection. A RSET command is issued before each
  9. delivery to ensure the correct SMTP handshake is followed.
  10. </para>
  11. <example id="zend.mail.multiple-emails.example-1">
  12. <title>Sending Multiple Mails per SMTP Connection</title>
  13. <programlisting language="php"><![CDATA[
  14. // Create transport
  15. $config = array('name' => 'sender.example.com');
  16. $transport = new Zend_Mail_Transport_Smtp('mail.example.com', $config);
  17. // Loop through messages
  18. for ($i = 0; $i < 5; $i++) {
  19. $mail = new Zend_Mail();
  20. $mail->addTo('studio@peptolab.com', 'Test');
  21. $mail->setFrom('studio@peptolab.com', 'Test');
  22. $mail->setSubject(
  23. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  24. );
  25. $mail->setBodyText('...Your message here...');
  26. $mail->send($transport);
  27. }
  28. ]]></programlisting>
  29. </example>
  30. <para>
  31. If you wish to have a separate connection for each mail
  32. delivery, you will need to create and destroy your transport before and
  33. after each <function>send()</function> method is called. Or alternatively,
  34. you can manipulate the connection between each delivery by accessing the
  35. transport's protocol object.
  36. </para>
  37. <example id="zend.mail.multiple-emails.example-2">
  38. <title>Manually controlling the transport connection</title>
  39. <programlisting language="php"><![CDATA[
  40. // Create transport
  41. $transport = new Zend_Mail_Transport_Smtp();
  42. $protocol = new Zend_Mail_Protocol_Smtp('mail.example.com');
  43. $protocol->connect();
  44. $protocol->helo('sender.example.com');
  45. $transport->setConnection($protocol);
  46. // Loop through messages
  47. for ($i = 0; $i < 5; $i++) {
  48. $mail = new Zend_Mail();
  49. $mail->addTo('studio@peptolab.com', 'Test');
  50. $mail->setFrom('studio@peptolab.com', 'Test');
  51. $mail->setSubject(
  52. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  53. );
  54. $mail->setBodyText('...Your message here...');
  55. // Manually control the connection
  56. $protocol->rset();
  57. $mail->send($transport);
  58. }
  59. $protocol->quit();
  60. $protocol->disconnect();
  61. ]]></programlisting>
  62. </example>
  63. </sect1>
  64. <!--
  65. vim:se ts=4 sw=4 et:
  66. -->