-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailer.php
More file actions
68 lines (57 loc) · 2.07 KB
/
mailer.php
File metadata and controls
68 lines (57 loc) · 2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require importer().'/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
// use PHPMailer\PHPMailer\Exception;
class Mailer {
static function sendMail($customerMail, $subject, $body, $altBody=null) : bool {
$myEmail = '';
$mail = new PHPMailer(true);
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Replace with your SMTP server
$mail->SMTPAuth = true;
$mail->Username = $myEmail; // Your email
$mail->Password = ''; // Your email password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom($myEmail, 'My custom name');
$mail->addAddress($customerMail); // Replace with recipient email
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $altBody ? $body : $altBody;
return $mail->send();
}
static function sendBulkMail($customerMails, $subject, $body, $altBody=null) {
$myEmail = '';
$mail = new PHPMailer(true);
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Replace with your SMTP server
$mail->SMTPAuth = true;
$mail->Username = $myEmail; // Your email
$mail->Password = ''; // Your email password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom($myEmail, 'My custom name');
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $altBody ? $body : $altBody;
// Send to each recipient individually
$response = [];
foreach ($customerMails as $email) {
$mail->clearAddresses(); // Clears previous recipient
$mail->addAddress($email);
if (!$mail->send()) {
$response[] = "Failed to send email to: $email. Error: {$mail->ErrorInfo}";
}
}
return $response;
}
}
?>