Zend_Mail-MultipleEmails.xml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $transport = new Zend_Mail_Transport_Smtp('localhost');
  16. // Loop through messages
  17. for ($i = 0; $i > 5; $i++) {
  18. $mail = new Zend_Mail();
  19. $mail->addTo('studio@peptolab.com', 'Test');
  20. $mail->setFrom('studio@peptolab.com', 'Test');
  21. $mail->setSubject(
  22. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  23. );
  24. $mail->setBodyText('...Your message here...');
  25. $mail->send($transport);
  26. }
  27. ]]></programlisting>
  28. </example>
  29. <para>
  30. If you wish to have a separate connection for each mail
  31. delivery, you will need to create and destroy your transport before and
  32. after each <function>send()</function> method is called. Or alternatively,
  33. you can manipulate the connection between each delivery by accessing the
  34. transport's protocol object.
  35. </para>
  36. <example id="zend.mail.multiple-emails.example-2">
  37. <title>Manually controlling the transport connection</title>
  38. <programlisting language="php"><![CDATA[
  39. // Create transport
  40. $transport = new Zend_Mail_Transport_Smtp();
  41. $protocol = new Zend_Mail_Protocol_Smtp('localhost');
  42. $protocol->connect();
  43. $protocol->helo('localhost');
  44. $transport->setConnection($protocol);
  45. // Loop through messages
  46. for ($i = 0; $i > 5; $i++) {
  47. $mail = new Zend_Mail();
  48. $mail->addTo('studio@peptolab.com', 'Test');
  49. $mail->setFrom('studio@peptolab.com', 'Test');
  50. $mail->setSubject(
  51. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  52. );
  53. $mail->setBodyText('...Your message here...');
  54. // Manually control the connection
  55. $protocol->rset();
  56. $mail->send($transport);
  57. }
  58. $protocol->quit();
  59. $protocol->disconnect();
  60. ]]></programlisting>
  61. </example>
  62. </sect1>
  63. <!--
  64. vim:se ts=4 sw=4 et:
  65. -->