class EmailService (View source)

Service responsible for composing and sending application emails using PHPMailer.

This service centralizes email-related operations, including:

  • Sending recovery codes
  • Loan reminders
  • Overdue loan notifications
  • Loan receipts
  • Loan extensions

Properties

protected PHPMailer $mailer

PHPMailer instance configured for SMTP.

Methods

__construct(PHPMailer $mailer)

EmailService constructor.

void
sendRecoveryCode(string $to, string $name, string $code)

Sends a 6-digit recovery code to a user.

void
sendLoanReminder(Loan $loan)

Sends a reminder email for a loan approaching its due date.

void
sendLoanOverdue(Loan $loan)

Sends a notification email for overdue loans.

void
sendLoanReceipt(Loan $loan)

Sends a loan receipt email immediately after loan creation.

void
sendLoanExtend(Loan $loan)

Sends an email notifying the borrower of a loan due-date extension.

array
prepareLoanData(Loan $loan)

Prepares loan data array for email templates.

void
sendEmail(string $to, string $name, string $subject, string $htmlBody, string $altBody)

Sends an email using PHPMailer.

Details

__construct(PHPMailer $mailer)

EmailService constructor.

Parameters

PHPMailer $mailer

fully configured PHPMailer instance

void sendRecoveryCode(string $to, string $name, string $code)

Sends a 6-digit recovery code to a user.

Parameters

string $to

recipient email address

string $name

recipient full name

string $code

recovery code

Return Value

void

Exceptions

Exception

void sendLoanReminder(Loan $loan)

Sends a reminder email for a loan approaching its due date.

Parameters

Loan $loan

loan instance

Return Value

void

Exceptions

Exception

void sendLoanOverdue(Loan $loan)

Sends a notification email for overdue loans.

Parameters

Loan $loan

loan instance

Return Value

void

Exceptions

Exception

void sendLoanReceipt(Loan $loan)

Sends a loan receipt email immediately after loan creation.

Parameters

Loan $loan

loan instance

Return Value

void

Exceptions

Exception

void sendLoanExtend(Loan $loan)

Sends an email notifying the borrower of a loan due-date extension.

Parameters

Loan $loan

loan instance

Return Value

void

Exceptions

Exception

protected array prepareLoanData(Loan $loan)

Prepares loan data array for email templates.

Parameters

Loan $loan

loan instance

Return Value

array

associative array of loan details

protected void sendEmail(string $to, string $name, string $subject, string $htmlBody, string $altBody)

Sends an email using PHPMailer.

Parameters

string $to

recipient email address

string $name

recipient full name

string $subject

email subject

string $htmlBody

HTML content of the email

string $altBody

plain-text alternative content

Return Value

void

Exceptions

Exception