1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* ZfMailer
|
4
|
|
|
*
|
5
|
|
|
* @author Daniel Wolkenhauer <[email protected]>
|
6
|
|
|
* @copyright Copyright (c) 1997-2019 Daniel Wolkenhauer
|
7
|
|
|
* @link http://dw-labs.de/zfmailer
|
8
|
|
|
* @version 0.1.0
|
9
|
|
|
*/
|
10
|
|
|
|
11
|
|
|
namespace ZfMailer\Service;
|
12
|
|
|
|
13
|
|
|
use Traversable;
|
14
|
|
|
use Zend\Mail\Transport;
|
15
|
|
|
use Zend\ServiceManager\FactoryInterface;
|
16
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface;
|
17
|
|
|
use Zend\Stdlib\ArrayUtils;
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* Mailer Factory
|
21
|
|
|
* Initilisiert den Transport-Service
|
22
|
|
|
*
|
23
|
|
|
* @package ZfMailer
|
24
|
|
|
* @subpackage Service
|
25
|
|
|
*/
|
26
|
|
|
class MailTransportFactory implements FactoryInterface
|
27
|
|
|
{
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* Create Service Factory
|
31
|
|
|
*
|
32
|
|
|
* @todo #ZFMAIL-1 - Konfiguration für SSL verbesern
|
33
|
|
|
* @param ServiceLocatorInterface $serviceLocator
|
34
|
|
|
*/
|
35
|
4 |
|
public function createService(ServiceLocatorInterface $serviceLocator)
|
36
|
|
|
{
|
37
|
|
|
|
38
|
4 |
|
$options = $serviceLocator->get('ZfMailerOptions');
|
39
|
|
|
|
40
|
4 |
|
$smartHost = $options->getSmartHost();
|
41
|
4 |
|
$ssl = null;
|
42
|
|
|
|
43
|
4 |
|
switch ($smartHost['server_port']) {
|
44
|
4 |
|
case '25':
|
45
|
1 |
|
$ssl = null;
|
46
|
1 |
|
break;
|
47
|
3 |
|
case '465':
|
48
|
1 |
|
$ssl = 'ssl';
|
49
|
1 |
|
break;
|
50
|
2 |
|
case '587':
|
51
|
1 |
|
$ssl = 'tls';
|
52
|
1 |
|
break;
|
53
|
|
|
|
54
|
|
|
default:
|
55
|
1 |
|
$ssl = null;
|
56
|
1 |
|
break;
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
$smtpOptions = array(
|
60
|
4 |
|
'host' => $smartHost['server_name'],
|
61
|
4 |
|
'port' => $smartHost['server_port'],
|
62
|
4 |
|
'connectionClass' => 'login',
|
63
|
|
|
'connectionConfig' => array(
|
64
|
4 |
|
'username' => $smartHost['username'],
|
65
|
4 |
|
'password' => $smartHost['password'],
|
66
|
|
|
),
|
67
|
|
|
);
|
68
|
|
|
|
69
|
4 |
|
if (isset($ssl) && !empty($ssl)) {
|
70
|
2 |
|
$smtpOptions['connectionConfig']['ssl'] = $ssl;
|
71
|
|
|
}
|
72
|
|
|
|
73
|
4 |
|
$transportOptions = new Transport\SmtpOptions($smtpOptions);
|
74
|
4 |
|
$transport = new Transport\Smtp($transportOptions);
|
75
|
|
|
|
76
|
4 |
|
return $transport;
|
77
|
|
|
|
78
|
|
|
}
|
79
|
|
|
|
80
|
|
|
}
|
81
|
|
|
|