-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
55 lines (43 loc) · 1.56 KB
/
mail.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load PHPMailer classes
require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';
// Create a new PHPMailer instance
function sendEmail($recipient = null, $recipient_name = null, $subject = null, $message = null) {
$mail = new PHPMailer(true);
try {
// Set mailer to use SMTP
$mail->isSMTP();
// Enable SMTP debugging (for testing)
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
// Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// Enable TLS encryption
$mail->SMTPSecure = 'tls';
// Set the SMTP port (465 for SSL, 587 for TLS)
$mail->Port = 587;
// Set your Gmail credentials
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Your Gmail address
$mail->Password = 'lctqxaoxacgoaxua'; // Your Gmail password
// Set the 'from' address and recipient
$mail->setFrom('[email protected]', 'Your Name');
$mail->addAddress($recipient, $recipient_name);
// Set email subject and body
$mail->Subject = $subject;
$mail->Body = $message;
$mail->isHTML(true);
// Send the email
$mail->send();
echo 'Email has been sent successfully';
} catch (Exception $e) {
echo "Mailer Error: {$mail->ErrorInfo}";
}
}
?>