SMTP Authentication - Zend_Mail

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');
  5. $transport = new Zend_Mail_Transport_Smtp('', $config);
  7. $mail = new Zend_Mail();
  8. $mail->setBodyText('This is the text of the mail.');
  9. $mail->setFrom('', 'Some Sender');
  10. $mail->addTo('', '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.


© 2006-2022 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.