|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SMTP Server class |
|
4
|
|
|
* |
|
5
|
|
|
* This file describes the SMTP Server class |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 5 and 7 |
|
8
|
|
|
* |
|
9
|
|
|
* @author Patrick Boyd / [email protected] |
|
10
|
|
|
* @copyright Copyright (c) 2016, Austin Artistic Reconstruction |
|
11
|
|
|
* @license http://www.apache.org/licenses/ Apache 2.0 License |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Email; |
|
15
|
|
|
|
|
16
|
|
|
require '/var/www/common/libs/PHPMailer/PHPMailerAutoload.php'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* An class to represent an SMTPSErver |
|
20
|
|
|
*/ |
|
21
|
|
|
class SMTPServer extends \Singleton |
|
22
|
|
|
{ |
|
23
|
|
|
protected $smtp; |
|
24
|
|
|
|
|
25
|
|
|
protected function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->smtp = new \SMTP(); |
|
28
|
|
|
$this->smtp->do_debug = \SMTP::DEBUG_LOWLEVEL; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function __destruct() |
|
32
|
|
|
{ |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function connect($hostName, $port=25, $useTLS=true) |
|
36
|
|
|
{ |
|
37
|
|
|
$ret = $this->smtp->connect($hostName, $port); |
|
38
|
|
|
if($ret === false) |
|
39
|
|
|
{ |
|
40
|
|
|
return $ret; |
|
41
|
|
|
} |
|
42
|
|
|
$ret = $this->smtp->hello('profiles.burningflipside.com'); |
|
43
|
|
|
if($ret === false) |
|
44
|
|
|
{ |
|
45
|
|
|
return $ret; |
|
46
|
|
|
} |
|
47
|
|
|
if($useTLS) |
|
48
|
|
|
{ |
|
49
|
|
|
$ret = $this->smtp->startTLS(); |
|
50
|
|
|
if($ret === false) |
|
51
|
|
|
{ |
|
52
|
|
|
return $ret; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
return $ret; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function authenticate($username, $password) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->smtp->authenticate($username, $password); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function sendOne($from, $to, $msgData) |
|
64
|
|
|
{ |
|
65
|
|
|
$ret = $this->smtp->mail($from); |
|
66
|
|
|
if($ret === false) |
|
67
|
|
|
{ |
|
68
|
|
|
return $ret; |
|
69
|
|
|
} |
|
70
|
|
|
$ret = $this->smtp->recipient($to); |
|
71
|
|
|
if($ret === false) |
|
72
|
|
|
{ |
|
73
|
|
|
return $ret; |
|
74
|
|
|
} |
|
75
|
|
|
return $this->smtp->data($msgData); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function disconnect() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->smtp->quit(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
84
|
|
|
?> |
|
|
|
|
|
|
85
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.