-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.php
More file actions
53 lines (41 loc) · 1.72 KB
/
mail.php
File metadata and controls
53 lines (41 loc) · 1.72 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
<?php
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class Mail {
public static function sendConfirmation($to,$subject, $message) {
$mail = new PHPMailer(true);
try {
// SMTP Settings
$mail->isSMTP();
$mail->Host = ''; // SMTP server
$mail->SMTPAuth = true;
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom('info@email.com', 'Company Name');
$mail->addAddress($to);
// Email Content
$mail->isHTML(true);
$mail->Subject = $subject;//"Booking Confirmation #$confirmationNumber";
$mail->Body = $message; //"Thank you for your booking. Your confirmation number is: <b>$confirmationNumber</b>";
$mail->send();
return true;
} catch (Exception $e) {
error_log("Mail Error: {$mail->ErrorInfo}");
//$this->logMessage("Mail Error: {$mail->ErrorInfo}");
file_put_contents("log.txt","Sending Email to:". $to." subject:".$subject." message:". $message, FILE_APPEND );
return false;
}
}
// Simple logging function
function logMessage($message) {
$logfile = 'log.txt'; // Adjust the path to where you want to store the log file
$currentDate = date("Y-m-d H:i:s");
file_put_contents($logfile, "[$currentDate] $message\n", FILE_APPEND);
}
}