Zend_Mail sending emails using SMTP with authentication

Altered somehow one site for would-be creators and it took me to send mail using SMTP c authentication.

Look in the manual on the website. http://framework.zend.com/manual/ru/zend.mail.smtp-authentication.html
see: "... at the moment the SMTP authentication is not supported" :(

What should I do?

Being well aware that the documentation on the website becomes obsolete before, and the latest version of the framework came out recently looking into the code.

And what do we see? Zend/Mail/Protocol/Smtp/Auth!!! CHEERS!

so, the result is:

config.ini (I store the configs in the ini-file)

[mail]
host = mailhost.ru
port = 25
auth = login
username = smtpusername
password = smtppassword


in accordance with the recommendation of manual
"to send an e-mail message via SMTP, you need to create and register a Zend_Mail_Transport_Smtp object before you call the send () method. All subsequent calls Zend_Mail::send() in the current script will use SMTP"

index.php or bootstrap.php

$oConfig = new Zend_Config_Ini('config.ini');

/**
* Mail setup. working through SMTP with authorization
*/
$tr = new Zend_Mail_Transport_Smtp( $oConfig->mail->host, $oConfig->mail->toArray() );
Zend_Mail::setDefaultTransport($tr);


here we should pay attention to the second parameter Zend_Mail_Transport_Smtp in accordance with the code is an array
/**
* Config options for authentication
*
* @var array
*/
protected $_config;

Zend_Mail_Transport_Smtp can't work with object configuration
that is why prihoditsja to convert it toArray()

and where to send only a helmet mail

$mail = new Zend_Mail( 'windows-1251' );
$mail- > setBodyText('This is the text of the mail.');
$mail- > setFrom('somebody@example.com', 'Some Sender');
$mail- > addTo('somebody_else@example.com', 'Some Recipient');
$mail- > setSubject('TestSubject');
$mail->send();
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Integration of PostgreSQL with MS SQL Server for those who want faster and deeper

Custom database queries in MODx Revolution

Google Web Mercator: a mixed coordinate system