forked from keterFree/posperity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
71 lines (58 loc) · 2.19 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Include PHPMailer autoload file
require 'vendor/autoload.php'; // Adjust the path as needed
// Function to send email
function sendEmail($to_email, $subject, $body, $from_email)
{
// Create a PHPMailer instance
$mail = new PHPMailer(true); // True enables exceptions
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
try {
// SMTP settings
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username (your email address)
$mail->Password = 'lrvq wsuc bihl garm'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption
$mail->Port = 587; // TCP port to connect to
// Sender and recipient details
$mail->setFrom($from_email, "Posperity team");
$mail->addAddress($to_email);
// Email content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
// $mail->SMTPDebug = 2; // Enable verbose SMTP debugging
// $mail->Debugoutput = 'html'; // Set debug output format to HTML
// Send email
$mail->send();
return true; // Email sent successfully
} catch (Exception $e) {
echo $e;
return false; // Email sending failed
}
}
function generateResetToken($length = 32)
{
// Define characters that can be used in the token
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Get the number of characters in the string
$charLength = strlen($characters);
// Initialize an empty token string
$token = '';
// Generate random characters to create the token
for ($i = 0; $i < $length; $i++) {
$token .= $characters[rand(0, $charLength - 1)];
}
// Return the generated token
return $token;
}