Zend_Mail-SmtpAuthentication.xml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!-- EN-Revision: 3803 Maintainer: mikespook Status: ready -->
  2. <sect1 id="zend.mail.smtp-authentication">
  3. <title>SMTP 身份验证</title>
  4. <para>
  5. <code>Zend_Mail</code> 支持使用 SMTP 身份验证,通过配置数组传递“auth”参数到 <code>Zend_Mail_Transport_Smtp</code> 的构造函数中。可用的内建身份验证方法为 PLAIN,LOGIN 和 CRAM-MD5,这些都需要在配置数组中设置“username”和“password”。
  6. </para>
  7. <example id="zend.mail.smtp-authentication.example-1">
  8. <title>在 Zend_Mail_Transport_Smtp 中使用身份验证</title>
  9. <programlisting role="php"><![CDATA[<?php
  10. require_once 'Zend/Mail.php';
  11. require_once 'Zend/Mail/Transport/Smtp.php';
  12. $config = array('auth' => 'login',
  13. 'username' => 'myusername',
  14. 'password' => 'password');
  15. $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
  16. $mail = new Zend_Mail();
  17. $mail->setBodyText('This is the text of the mail.');
  18. $mail->setFrom('sender@test.com', 'Some Sender');
  19. $mail->addTo('recipient@test.com', 'Some Recipient');
  20. $mail->setSubject('TestSubject');
  21. $mail->send($transport);]]>
  22. </programlisting>
  23. </example>
  24. <note>
  25. <title>身份验证类型</title>
  26. <para>
  27. 身份验证的类型是大小写不敏感的,但是不能有标点符号。例如,使用 CRAM-MD5 类型,则应当传递 'auth' => 'crammd5' 到 <code>Zend_Mail_Transport_Smtp</code> 的构造函数中。
  28. </para>
  29. </note>
  30. </sect1>
  31. <!--
  32. vim:se ts=4 sw=4 et:
  33. -->