Language updates. New upload form. new classes.
This commit is contained in:
parent
4c2857b445
commit
8f3061ab99
62 changed files with 3107 additions and 1883 deletions
73
classes/Email.php
Normal file
73
classes/Email.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
use Aws\Ses\SesClient;
|
||||
use Aws\Exception\AwsException;
|
||||
use Exception;
|
||||
|
||||
class Email {
|
||||
|
||||
private $config;
|
||||
private $sesClient;
|
||||
|
||||
public function __construct(array $config) {
|
||||
$this->config = $config;
|
||||
$this->sesClient = new SesClient([
|
||||
'version' => 'latest',
|
||||
'region' => $config['aws']['ses']['region'],
|
||||
'credentials' => [
|
||||
'key' => $config['aws']['ses']['access_key'],
|
||||
'secret' => $config['aws']['ses']['secret_key']
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method to send an email.
|
||||
*
|
||||
* @param string $recipientEmail
|
||||
* @param string $subject
|
||||
* @param string $bodyText
|
||||
* @throws Exception if email sending fails.
|
||||
*/
|
||||
public function sendEmail(string $recipientEmail, string $subject, string $bodyText): void {
|
||||
$senderEmail = $this->config['aws']['ses']['sender_email'];
|
||||
try {
|
||||
$this->sesClient->sendEmail([
|
||||
'Destination' => ['ToAddresses' => [$recipientEmail]],
|
||||
'ReplyToAddresses' => [$senderEmail],
|
||||
'Source' => $senderEmail,
|
||||
'Message' => [
|
||||
'Body' => [
|
||||
'Text' => [
|
||||
'Charset' => 'UTF-8',
|
||||
'Data' => $bodyText,
|
||||
],
|
||||
],
|
||||
'Subject' => [
|
||||
'Charset' => 'UTF-8',
|
||||
'Data' => $subject,
|
||||
],
|
||||
],
|
||||
]);
|
||||
} catch (AwsException $e) {
|
||||
throw new Exception("Failed to send email: " . $e->getAwsErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to send a verification email.
|
||||
*
|
||||
* @param string $recipientEmail
|
||||
* @param string $verificationCode
|
||||
* @throws Exception if email sending fails.
|
||||
*/
|
||||
public function sendVerificationEmail(string $recipientEmail, string $verificationCode): void {
|
||||
$subject = "Verify Your Email Address";
|
||||
$verificationLink = $this->config['app']['url'] . "/verify_email.php?code={$verificationCode}";
|
||||
$bodyText = "Please verify your email address by clicking the link below or by entering the code in your profile:\n\n";
|
||||
$bodyText .= "{$verificationLink}\n\nYour verification code is: {$verificationCode}\nThis code will expire in 15 minutes.";
|
||||
$this->sendEmail($recipientEmail, $subject, $bodyText);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue