-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMTPEMail.php
87 lines (76 loc) · 2.2 KB
/
SMTPEMail.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
<?php
require_once __DIR__ . '/PHPMailer/Exception.php';
require_once __DIR__ . '/PHPMailer/PHPMailer.php';
require_once __DIR__ . '/PHPMailer/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class SMTPEMail
{
private PHPMailer $fPHPMailer;
/**
* Initialize a new smtpemail object
* @param string $smtpHostName
* @param int $smtpPort
* @param string $smtpUsername
* @param string $smtpPassword
*/
public function __construct(string $smtpHostName, int $smtpPort, string $smtpUsername, string $smtpPassword, string $encryption = "")
{
$this->fPHPMailer = new PHPMailer(true);
$this->fPHPMailer->isSMTP();
$this->fPHPMailer->CharSet = 'UTF-8';
$this->fPHPMailer->Host = $smtpHostName;
$this->fPHPMailer->SMTPAuth = true;
$this->fPHPMailer->Username = $smtpUsername;
$this->fPHPMailer->Password = $smtpPassword;
$this->fPHPMailer->SMTPSecure = $encryption;
$this->fPHPMailer->Port = $smtpPort;
$this->fPHPMailer->isHTML = true;
}
/**
* Sets senders information
* @param string $emailAddress
* @param string $senderName
* @return void
*/
public function setFrom(string $emailAddress, string $senderName): void
{
$this->fPHPMailer->setFrom($emailAddress, $senderName);
}
/**
* Add a recipient to your email
* @param string $recipientsEmailAddress
* @return void
*/
public function addTo(string $recipientsEmailAddress): void
{
$this->fPHPMailer->addAddress($recipientsEmailAddress);
}
/**
* Set subject
* @param string $subject
*/
public function setSubject(string $subject)
{
$this->fPHPMailer->Subject = $subject;
}
/**
* Set HTML Message
* @param string $html
*/
public function setHtmlMessage(string $html)
{
$this->fPHPMailer->isHTML(true);
$this->fPHPMailer->Body = $html;
$this->fPHPMailer->AltBody = strip_tags($this->fPHPMailer->Body);
}
/**
* Send the email
* @return bool
*/
public function Send(): bool
{
return $this->fPHPMailer->send();
}
}
?>