-
Notifications
You must be signed in to change notification settings - Fork 0
/
observer.php
92 lines (68 loc) · 2.97 KB
/
observer.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
<?php
interface IObserver
{
//an observer has to implement a function, that will be called when the observable changes
//the function receive data (in this case the user name) and also the observable object (since the observer could be observing more than on system)
function onUserAdded( $observable, $data );
function mail_admin ($admin_mail, $usertype, $data);
}
class NewUserMailer implements IObserver
{
public function onUserAdded( $observable, $data )
{
$this->mail_admin("tofiq@yopmail.com", "new user", $data);
}
public function mail_admin($admin_mail, $usertype, $data) {
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'askuofr@gmail.com'; // SMTP username
$mail->Password = 'savanmanoj'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('from@example.com', 'SplitNShare Webmaster');
$mail->addAddress($admin_mail, 'tofiq');
$mail->addAddress(''); // Name is optional
$mail->addReplyTo('', '');
$mail->addCC('');
$mail->addBCC('');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'User ' . $data . ' added';
$mail->Body = 'Group member ' . $data . ' registered for group' ;
$mail->AltBody = '';
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
}
interface IObservable
{
//we can attach observers to the observable
function attach( $observer );
}
class LoginSystem implements IObservable
{
private $observers = array();
private function notify( $userName )
{
foreach( $this->observers as $o )
$o->onUserAdded( $this, $userName );
}
public function attach( $observer )
{
$this->observers []= $observer;
}
public function createUser( $userName )
{
//al your logic to add it to the databse or whatevere, andt then:
$this->notify($userName);
}
}