Add petition-specific SMTP configuration support
Allow separate SMTP account for petition emails to improve deliverability through proper SPF/DKIM configuration matching the from address
This commit is contained in:
parent
609bd5dd34
commit
798bf268aa
3 changed files with 45 additions and 18 deletions
|
|
@ -266,8 +266,14 @@ function sendEmail(string $to, string $toName, string $subject, string $body): a
|
|||
$fromEmail = $config['petition']['from_email'] ?? $config['from_email'];
|
||||
$fromName = $config['petition']['from_name'] ?? $config['from_name'];
|
||||
|
||||
// Get petition-specific SMTP settings (allows separate SMTP account for better deliverability)
|
||||
$smtpHost = $config['petition']['host'] ?? $config['host'];
|
||||
$smtpPort = $config['petition']['port'] ?? $config['port'];
|
||||
$smtpUser = $config['petition']['username'] ?? $config['username'];
|
||||
$smtpPass = $config['petition']['password'] ?? $config['password'];
|
||||
|
||||
// Pre-flight check
|
||||
$fp = @fsockopen($config['host'], $config['port'], $errno, $errstr, 10);
|
||||
$fp = @fsockopen($smtpHost, $smtpPort, $errno, $errstr, 10);
|
||||
if (!$fp) {
|
||||
return ['success' => false, 'error' => "Tilkobling feilet: {$errno} - {$errstr}"];
|
||||
}
|
||||
|
|
@ -278,10 +284,10 @@ function sendEmail(string $to, string $toName, string $subject, string $body): a
|
|||
|
||||
$mail = new \codeworxtech\PHPMailerLite\PHPMailerLite();
|
||||
|
||||
$mail->SetSMTPhost($config['host']);
|
||||
$mail->SetSMTPport($config['port']);
|
||||
$mail->SetSMTPuser($config['username']);
|
||||
$mail->SetSMTPpass($config['password']);
|
||||
$mail->SetSMTPhost($smtpHost);
|
||||
$mail->SetSMTPport($smtpPort);
|
||||
$mail->SetSMTPuser($smtpUser);
|
||||
$mail->SetSMTPpass($smtpPass);
|
||||
|
||||
$mail->SetSender([$fromEmail => $fromName]);
|
||||
$mail->AddRecipient([$to => $toName]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue