SMTP Authentication

Zend_Mail supports the use of SMTP authentication, which can be enabled be passing the 'auth' parameter to the configuration array in the Zend_Mail_Transport_Smtp constructor. The available built-in authentication methods are PLAIN, LOGIN and CRAM-MD5 which all expect a 'username' and 'password' value in the configuration array.

Example #1 Enabling authentication within Zend_Mail_Transport_Smtp

  1. $config = array('auth' => 'login',
  2.                 'username' => 'myusername',
  3.                 'password' => 'password');
  4.  
  5. $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
  6.  
  7. $mail = new Zend_Mail();
  8. $mail->setBodyText('This is the text of the mail.');
  9. $mail->setFrom('sender@test.com', 'Some Sender');
  10. $mail->addTo('recipient@test.com', 'Some Recipient');
  11. $mail->setSubject('TestSubject');
  12. $mail->send($transport);

Note: Authentication types
The authentication type is case-insensitive but has no punctuation. E.g. to use CRAM-MD5 you would pass 'auth' => 'crammd5' in the Zend_Mail_Transport_Smtp constructor.

blog comments powered by Disqus