This repository was archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.class.php
More file actions
56 lines (42 loc) · 1.35 KB
/
Email.class.php
File metadata and controls
56 lines (42 loc) · 1.35 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
<?php
require("./sendgrid-php/sendgrid-php.php");
class Email {
private $email;
private $sendgrid;
private $config;
private $hasContent;
private $hasSubject;
public function __construct($toEmail, $toName) {
$this->hasContent = false;
$this->hasSubject = false;
$this->config = parse_ini_file("config.ini.php");
$this->email = new \SendGrid\Mail\Mail();
$this->email->setFrom($this->config['from_email'], $this->config['from_name']);
$this->email->setSubject($this->config['website_name']);
$this->email->addTo($toEmail, $toName);
$this->sendgrid = new \SendGrid($this->config['SENDGRID_API_KEY']);
}
public function setPlain($plain) {
$this->email->addContent(
"text/plain", $plain
);
}
public function setSubject($subject) {
$this->email->setSubject($subject);
$this->hasSubject = true;
}
public function setHtml($html) {
$this->email->addContent(
"text/html", $html
);
$this->hasContent = true;
}
public function send() {
if(!$this->hasSubject || !$this->hasContent) {
throw new Exception("Email HTML content and/or Subject missing!");
}
$response = $this->sendgrid->send($this->email);
return $response;
}
}
?>