1

私はこれを試しましたが、私にとってはうまくいきませんでした。 https://stackoverflow.com/questions/10537318/how-to-use-the-di-for-zend-mail-transport-smtp

Zend フレームワーク 2.0.3dev を使用しています

4

2 に答える 2

18

私にとって、これはGoogleアプリのメールアドレスで機能しました

config/autoload/mail.local.php

return array(
'mail' => array(
    'transport' => array(
        'options' => array(
            'host'              => 'smtp.gmail.com',
            'connection_class'  => 'plain',
            'connection_config' => array(
                'username' => 'example@example.org',
                'password' => '',
                'ssl' => 'tls'
            ),
        ),  
    ),
),
);

そしてModule.php

public function getServiceConfig()
{
    return array(
        'factories' => array(
            'mail.transport' => function (ServiceManager $serviceManager) {
                $config = $serviceManager->get('Config'); 
                $transport = new Smtp();                
                $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));

                return $transport;
            },
        ),
    );
}

そしてコントローラーで

$transport = $this->getServiceLocator()->get('mail.transport');

このコードが誰かの役に立つことを願っています:D

于 2012-10-09T09:26:30.573 に答える