Initial commit
This commit is contained in:
45
api/includes/Mailer.php
Normal file
45
api/includes/Mailer.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* BOHA Automation - Email Helper
|
||||
*
|
||||
* Sends emails via PHP mail() function.
|
||||
* Configuration via .env variables.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class Mailer
|
||||
{
|
||||
/**
|
||||
* Send an email
|
||||
*
|
||||
* @param string $to Recipient email address
|
||||
* @param string $subject Email subject (plain text, will be UTF-8 encoded)
|
||||
* @param string $htmlBody HTML email body
|
||||
* @param string|null $replyTo Optional reply-to address
|
||||
* @return bool True if sent successfully
|
||||
*/
|
||||
public static function send(string $to, string $subject, string $htmlBody, ?string $replyTo = null): bool
|
||||
{
|
||||
$fromEmail = env('SMTP_FROM_EMAIL', env('CONTACT_EMAIL_FROM', 'web@boha-automation.cz'));
|
||||
$fromName = env('SMTP_FROM_NAME', 'BOHA Automation');
|
||||
|
||||
$encodedSubject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
|
||||
|
||||
$headers = "MIME-Version: 1.0\r\n";
|
||||
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
|
||||
$headers .= "From: $fromName <$fromEmail>\r\n";
|
||||
if ($replyTo) {
|
||||
$headers .= "Reply-To: $replyTo\r\n";
|
||||
}
|
||||
|
||||
$sent = mail($to, $encodedSubject, $htmlBody, $headers);
|
||||
|
||||
if (!$sent) {
|
||||
error_log("Mailer error: mail() failed for recipient $to");
|
||||
}
|
||||
|
||||
return $sent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user