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
|
|
@ -713,11 +713,17 @@ function petitionSendConfirmationEmailInternal(array $data, string $confirmUrl,
|
|||
|
||||
$subject = petitionT($ctx, 'petition', 'email_subject');
|
||||
|
||||
// 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) {
|
||||
$errorMessage = "Connection failed: {$errno} - {$errstr}";
|
||||
error_log("Petition SMTP pre-flight failed: {$config['host']}:{$config['port']} - {$errno} - {$errstr}");
|
||||
error_log("Petition SMTP pre-flight failed: {$smtpHost}:{$smtpPort} - {$errno} - {$errstr}");
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
|
|
@ -727,10 +733,10 @@ function petitionSendConfirmationEmailInternal(array $data, string $confirmUrl,
|
|||
|
||||
$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);
|
||||
|
||||
$recipientName = $data['firstname'] . ' ' . $data['surname'];
|
||||
$mail->SetSender([$fromEmail => $fromName]);
|
||||
|
|
@ -859,11 +865,17 @@ function petitionSendThankYouEmailInternal(string $token, string $deleteUrl, str
|
|||
|
||||
$subject = petitionT($ctx, 'petition', 'email_thankyou_subject');
|
||||
|
||||
// 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) {
|
||||
$errorMessage = "Connection failed: {$errno} - {$errstr}";
|
||||
error_log("Petition SMTP pre-flight failed: {$config['host']}:{$config['port']} - {$errno} - {$errstr}");
|
||||
error_log("Petition SMTP pre-flight failed: {$smtpHost}:{$smtpPort} - {$errno} - {$errstr}");
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
|
|
@ -873,10 +885,10 @@ function petitionSendThankYouEmailInternal(string $token, string $deleteUrl, str
|
|||
|
||||
$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);
|
||||
|
||||
$recipientName = $signature['firstname'] . ' ' . $signature['surname'];
|
||||
$mail->SetSender([$fromEmail => $fromName]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue