AbstractEmail::realSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base class for email messaging
4
 *
5
 * @file      AbstractEmail.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Alexander Yancharuk <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk
11
 * @date      Втр Июл 17 21:58:01 2012
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Email;
17
18
/**
19
 * Класс AbstractEmail
20
 * @author  Alexander Yancharuk <alex at itvault dot info>
21
 */
22
abstract class AbstractEmail
23
{
24
	protected $receivers = [];
25
	protected $headers   = '';
26
	protected $subject   = null;
27
	protected $message   = null;
28
	protected $charset   = 'utf-8';
29
	protected $encoding  = 'base64';   //8bit
30
31
	/**
32
	 * Create message
33
	 */
34
	abstract public function init();
35
36
	/**
37
	 * Send emails
38
	 */
39 5
	public function send()
40
	{
41 5
		foreach ($this->receivers as $receiver) {
42 4
			$this->realSend($receiver);
43
		}
44
	}
45
46
	/**
47
	 * Send email
48
	 *
49
	 * @param string $receiver
50
	 * @codeCoverageIgnore
51
	 *
52
	 * @return bool
53
	 */
54
	protected function realSend($receiver)
55
	{
56
		return mail($receiver, $this->subject, $this->message, $this->headers);
57
	}
58
59
	/**
60
	 * Set message recipients
61
	 *
62
	 * @param array $receivers Emails of receivers
63
	 */
64 5
	public function setReceivers(array $receivers)
65
	{
66 5
		$this->receivers = $receivers;
67
	}
68
69
	/**
70
	 * Set email subject
71
	 *
72
	 * @param string $subject Email subject
73
	 */
74 1
	public function setSubject($subject)
75
	{
76 1
		$encoded_subj = base64_encode($subject);
77 1
		$charset = $this->getCharset();
78 1
		$this->subject = "=?$charset?B?$encoded_subj?=";
79
	}
80
81
	/**
82
	 * @return string
83
	 */
84 2
	public function getCharset()
85
	{
86 2
		return $this->charset;
87
	}
88
89
	/**
90
	 * @param string $charset
91
	 */
92 1
	public function setCharset($charset)
93
	{
94 1
		$this->charset = $charset;
95
	}
96
97
	/**
98
	 * @return string
99
	 */
100 2
	public function getEncoding()
101
	{
102 2
		return $this->encoding;
103
	}
104
105
	/**
106
	 * @param string $encoding
107
	 */
108 1
	public function setEncoding($encoding)
109
	{
110 1
		$this->encoding = $encoding;
111
	}
112
}
113