-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.php
51 lines (43 loc) · 1.37 KB
/
mailer.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
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
include_once(__DIR__.'/vendor/autoload.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendMail($recepient){
//$mail = new PHPMailer(true);
$mail = new PHPMailer();
try {
//Server settings
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
));
//$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Username = '';
$mail->Password = '';
$mail->SetFrom('mailAddress', 'SenderName');
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPAutoTLS = false;
$mail->Port = 587;
//Recipients
$mail->addAddress($recepient['email'], $recepient['name'] ?? "SenderName");
// Content
$mail->isHTML(true);
$mail->Subject = $recepient['subject'] ?? "Upwork Jobs Alert";
$mail->Body = $recepient['mail_body'];
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
return $mail->send();
//echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false;
}
}