isSMTP(); $mail->Host = MAIL_HOST; $mail->SMTPAuth = true; $mail->Username = MAIL_USERNAME; $mail->Password = MAIL_PASSWORD; $mail->SMTPSecure = MAIL_ENCRYPTION === 'ssl' ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = MAIL_PORT; $mail->CharSet = 'UTF-8'; $mail->setFrom(MAIL_FROM, MAIL_FROM_NAME); $mail->addAddress($toEmail, $toName); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $htmlBody; $mail->AltBody = $textBody ?? strip_tags($htmlBody); $mail->send(); return ['success' => true, 'error' => '']; } catch (MailerException $e) { error_log('Mailer error to ' . $toEmail . ': ' . $mail->ErrorInfo); return ['success' => false, 'error' => $mail->ErrorInfo]; } } /** * Send a password reset email. */ function sendPasswordResetEmail(string $email, string $token): bool { $resetUrl = 'https://cropmonitor.com.au/login/reset-password.php?token=' . urlencode($token); $html = '

Crop Monitor — Password Reset

We received a request to reset your password. Click the button below to choose a new one.

Reset My Password

This link expires in 1 hour. If you did not request a password reset, you can safely ignore this email.


Crop Monitor — Australian Crop Management Platform

'; $text = "Crop Monitor — Password Reset\n\n" . "Click the link below to reset your password (expires in 1 hour):\n\n" . $resetUrl . "\n\n" . "If you did not request this, ignore this email."; $result = sendMail($email, $email, 'Reset your Crop Monitor password', $html, $text); return $result['success']; } /** * Send a welcome email after registration. */ function sendWelcomeEmail(string $email, string $fullname): bool { $loginUrl = 'https://cropmonitor.com.au/login/login.php'; $html = '

Welcome to Crop Monitor!

Hi ' . htmlspecialchars($fullname, ENT_QUOTES, 'UTF-8') . ',

Your account has been created. You can now log in and start managing your crop analysis records.

Go to Crop Monitor

If you have any questions, reply to this email and we will get back to you.


Crop Monitor — Australian Crop Management Platform

'; $text = "Welcome to Crop Monitor, {$fullname}!\n\n" . "Your account has been created. Log in here:\n\n" . $loginUrl . "\n\n" . "If you have any questions, reply to this email."; $result = sendMail($email, $fullname, 'Welcome to Crop Monitor', $html, $text); return $result['success']; }