1

我试过这个,但对我来说没有用。 https://stackoverflow.com/questions/10537318/how-to-use-the-di-for-zend-mail-transport-smtp

我使用 zend 框架 2.0.3dev

4

2 回答 2

18

对我来说,这适用于谷歌应用邮件地址

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 回答
1
Try:
$objEmail = new \Zend\Mail\Message();
$objEmail->setBody('Message here');
$objEmail->setFrom('from@domain.com', 'From');
$objEmail->addTo('to@domain.com', 'To');
$objEmail->setSubject('Subject here');
// Setup SMTP transport using PLAIN authentication over TLS
$transport = new \Zend\Mail\Transport\Smtp();
$options = new \Zend\Mail\Transport\SmtpOptions(array(
    'name' => 'smtp.gmail.com',
    'host' => 'smtp.gmail.com',
    'port' => 587, // Notice port change for TLS is 587
    'connection_class' => 'plain',
    'connection_config' => array(
        'username' => '',
        'password' => '',
        'ssl' => 'tls',
    ),
));
$transport->setOptions($options);
$transport->send($objEmail); 
于 2015-11-01T11:14:45.480 回答