forked from mayflower/PHProjekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mail.php
104 lines (94 loc) · 3.35 KB
/
Mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3 as published by the Free Software Foundation
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* @copyright Copyright (c) 2010 Mayflower GmbH (http://www.mayflower.de)
* @license LGPL v3 (See LICENSE file)
*/
/**
* Mail class.
*/
class Phprojekt_Mail extends Zend_Mail
{
/**
* External use (configuration.php):
*/
const LINEEND_RN = 0;
const LINEEND_N = 1;
const TRANSPORT_SMTP = 0;
const TRANSPORT_SENDMAIL = 1;
/**
* Sets the SMTP server.
*
* The data is obtained from the configuration.php file.
*
* @return Zend_Mail_Transport_Smtp|Zend_Mail_Transport_Sendmail Object
*/
public function setTransport()
{
switch (Phprojekt::getInstance()->getConfig()->mailTransport) {
case self::TRANSPORT_SMTP:
default:
$smtpServer = Phprojekt::getInstance()->getConfig()->smtpServer;
$smtpAuth = Phprojekt::getInstance()->getConfig()->smtpAuth;
$smtpUser = Phprojekt::getInstance()->getConfig()->smtpUser;
$smtpPassword = Phprojekt::getInstance()->getConfig()->smtpPassword;
$smtpSsl = Phprojekt::getInstance()->getConfig()->smtpSsl;
$smtpPort = Phprojekt::getInstance()->getConfig()->smtpPort;
if (empty($smtpServer)) {
$smtpServer = 'localhost';
}
$parameters = array();
if (!empty($smtpAuth)) {
$parameters['auth'] = $smtpAuth;
}
if (!empty($smtpUser)) {
$parameters['username'] = $smtpUser;
}
if (!empty($smtpPassword)) {
$parameters['password'] = $smtpPassword;
}
if (!empty($smtpSsl)) {
$parameters['ssl'] = $smtpSsl;
}
if (!empty($smtpPort)) {
$parameters['port'] = $smtpPort;
}
if (empty($parameters)) {
$smtpTransport = new Zend_Mail_Transport_Smtp($smtpServer);
} else {
$smtpTransport = new Zend_Mail_Transport_Smtp($smtpServer, $parameters);
}
break;
case self::TRANSPORT_SENDMAIL:
$smtpTransport = new Zend_Mail_Transport_Sendmail();
break;
}
return $smtpTransport;
}
/**
* Returns the string used for end of line in text mode emails, according to config file setting.
*
* @return string End of line characters.
*/
protected function getEndOfLine()
{
switch (Phprojekt::getInstance()->getConfig()->mailEndOfLine) {
case self::LINEEND_N:
$endOfLine = "\n";
break;
case self::LINEEND_RN:
default:
$endOfLine = "\r\n";
break;
}
return $endOfLine;
}
}