-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail.php
59 lines (52 loc) · 1.68 KB
/
email.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
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
/**
* Sends an email to a given address.
*
* @param $subscriberName
* @param $subscriberMail
* @param $mailingList
* @param string $subject
* @param string $body
*
* @return bool
*/
function sendMail($subscriberName, $subscriberMail, $mailingList, $subject, $body)
{
$mail = new PHPMailer(TRUE);
try {
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output. */
$mail->isSMTP();
/* https://stackoverflow.com/questions/2491475/phpmailer-character-encoding-issues */
$mail->Encoding = 'base64';
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = TRUE;
$mail->SMTPKeepAlive = TRUE;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
'allow_self_signed' => TRUE
]
];
$mail->Host = getEnvVar('EMAIL_HOST');
$mail->Port = getEnvVar('EMAIL_PORT');
$mail->Password = getEnvVar('SENDER_PASSWORD');
$mail->Username = getEnvVar('SENDER_USERNAME');
$mail->setFrom($subscriberMail, $subscriberName);
$mail->addAddress($mailingList);
$mail->isHTML();
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
return TRUE;
} catch (Exception $exception) {
return FALSE;
}
}