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); } }