Skip to content
Permalink
Browse files

Add mail_no_reply_avoid_reply_to conf setting #2699

Avoid add a reply-to header when a no-reply address is set.
  • Loading branch information...
AngelFQC committed Mar 7, 2019
1 parent d49ee90 commit 6a758d8a524c383ceab9a1ce73b026527bfc5c2b
Showing with 68 additions and 35 deletions.
  1. +65 −35 main/inc/lib/api.lib.php
  2. +3 −0 main/install/configuration.dist.php
@@ -8779,43 +8779,14 @@ function api_mail_html(
$mail->Priority = 3;
$mail->SMTPKeepAlive = true;
// Default values
$notification = new Notification();
$defaultEmail = $notification->getDefaultPlatformSenderEmail();
$defaultName = $notification->getDefaultPlatformSenderName();
// If the parameter is set don't use the admin.
$senderName = !empty($senderName) ? $senderName : $defaultName;
$senderEmail = !empty($senderEmail) ? $senderEmail : $defaultEmail;
// Reply to first
if (isset($extra_headers['reply_to']) && empty($platform_email['SMTP_UNIQUE_REPLY_TO'])) {
if (PHPMailer::validateAddress($extra_headers['reply_to']['mail'])) {
$mail->AddReplyTo(
$extra_headers['reply_to']['mail'],
$extra_headers['reply_to']['name']
);
// Errors to sender
$mail->AddCustomHeader('Errors-To: '.$extra_headers['reply_to']['mail']);
$mail->Sender = $extra_headers['reply_to']['mail'];
unset($extra_headers['reply_to']);
}
} else {
$mail->AddCustomHeader('Errors-To: '.$defaultEmail);
}
api_set_noreply_and_from_address_to_mailer(
$mail,
['name' => $senderName, 'email' => $senderEmail],
!empty($extra_headers['reply_to']) ? $extra_headers['reply_to'] : []
);
//If the SMTP configuration only accept one sender
if (isset($platform_email['SMTP_UNIQUE_SENDER']) && $platform_email['SMTP_UNIQUE_SENDER']) {
$senderName = $platform_email['SMTP_FROM_NAME'];
$senderEmail = $platform_email['SMTP_FROM_EMAIL'];
$valid = PHPMailer::validateAddress($senderEmail);
if ($valid) {
//force-set Sender to $senderEmail, otherwise SetFrom only does it if it is currently empty
$mail->Sender = $senderEmail;
}
}
unset($extra_headers['reply_to']);
$mail->SetFrom($senderEmail, $senderName);
$mail->Subject = $subject;
$mail->AltBody = strip_tags(
str_replace('<br />', "\n", api_html_entity_decode($message))
@@ -9394,3 +9365,62 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
['allowed_classes' => $allowedClasses]
);
}
/**
* Set the From and ReplyTo properties to PHPMailer instance.
*
* @param PHPMailer $mailer
* @param array $sender
* @param array $replyToAddress
*
* @throws phpmailerException
*/
function api_set_noreply_and_from_address_to_mailer(PHPMailer $mailer, array $sender, array $replyToAddress = [])
{
$platformEmail = $GLOBALS['platform_email'];
$noReplyAddress = api_get_setting('noreply_email_address');
$avoidReplyToAddress = false;
if (!empty($noReplyAddress)) {
$avoidReplyToAddress = api_get_configuration_value('mail_no_reply_avoid_reply_to');
}
$notification = new Notification();
// If the parameter is set don't use the admin.
$senderName = !empty($sender['name']) ? $sender['name'] : $notification->getDefaultPlatformSenderName();
$senderEmail = !empty($sender['email']) ? $sender['email'] : $notification->getDefaultPlatformSenderEmail();
// Reply to first
if (!$avoidReplyToAddress) {
$mailer->AddCustomHeader('Errors-To: '.$notification->getDefaultPlatformSenderEmail());
if (
!empty($replyToAddress) &&
$platformEmail['SMTP_UNIQUE_REPLY_TO'] &&
PHPMailer::ValidateAddress($replyToAddress['mail'])
) {
$mailer->AddReplyTo($replyToAddress['email'], $replyToAddress['name']);
// Errors to sender
$mailer->AddCustomHeader('Errors-To: '.$replyToAddress['mail']);
$mailer->Sender = $replyToAddress['mail'];
}
}
//If the SMTP configuration only accept one sender
if (
isset($platformEmail['SMTP_UNIQUE_SENDER']) &&
$platformEmail['SMTP_UNIQUE_SENDER']
) {
$senderName = $platformEmail['SMTP_FROM_NAME'];
$senderEmail = $platformEmail['SMTP_FROM_EMAIL'];
if (PHPMailer::ValidateAddress($senderEmail)) {
//force-set Sender to $senderEmail, otherwise SetFrom only does it if it is currently empty
$mailer->Sender = $senderEmail;
}
}
$mailer->SetFrom($senderEmail, $senderName, !$avoidReplyToAddress);
}
@@ -1140,3 +1140,6 @@
// You need add a new option called "confirmation" to the registration settings
//INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_registration', 'confirmation', 'MailConfirmation');
// ------ (End) Custom DB changes
// Avoid add a reply-to header when a no-reply address is set.
//$_configuration['mail_no_reply_avoid_reply_to'] = false;

0 comments on commit 6a758d8

Please sign in to comment.
You can’t perform that action at this time.