-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailInformer.php
More file actions
59 lines (46 loc) · 1.46 KB
/
EmailInformer.php
File metadata and controls
59 lines (46 loc) · 1.46 KB
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
<?php
abstract class EmailInformer {
abstract protected function setMail();
public function send() {
echo "Message '$this->message' has been sent to $this->email";
}
}
class GoogleInformer extends EmailInformer {
protected $message;
protected $email;
public function __construct($message, $email) {
$this->message = $message;
$this->email = $email;
if($this->setMail($email)) {
$this->send();
}
}
protected function setMail() {
if(preg_match('/^([a-z0-9_\.-]+)@gmail\.com$/', $this->email)) {
return true;
}
else echo 'Email adress should be "******@gmail.com"';
}
}
class YandexInformer extends EmailInformer {
protected $message;
protected $email;
public function __construct($message, $email) {
$this->message = $message;
$this->email = $email;
if($this->setMail($email)) {
$this->send();
}
}
protected function setMail() {
if(preg_match('/^([a-z0-9_\.-]+)@yandex\.ru$/', $this->email)) {
return true;
}
else echo 'Email adress should be "******@yandex.ru"';
}
}
$sendToGoogle = new GoogleInformer('lalalalala', 'vswekid@gmail.com');
echo '<br>';
$sendToYandex = new YandexInformer('lalalalfaefef fsefala', 'fefe@yandex.ru');
echo '<br>';
$sendToYandex = new YandexInformer('lalalalfaefef fsefala', 'wrongAdress@wrong.ru');