Permanent Change X-Mailer header

nemesis82

Active Member
Hy guys,
there is a way to permanent change the X-Mailer headeer ?
I need remove the mailer version ( switfmailer x.x.x , phpmailer x.x.x )
If i change the mailer php file, in the next update it will be rewrited and if i set it in Delivery Server option it came overwritten from php mailer file .
there is a custom ini file to create?
 

nemesis82

Active Member
@twisted1919 , thanks for your reply but i don't need to remove the header, i must change it with a custom parameter.
eg.
from swiftmail 5.4.x to swiftmail ( without version )
 

twisted1919

Administrator
Staff member
Try: (not tested)
Code:
Yii::app()->hooks->addFilter('console_command_send_campaigns_before_send_to_subscriber', function($emailParams, $campaign, $subscriber, $customer, $server){
    foreach ($emailParams['headers'] as $index => $header) {
        if ($header['name'] == 'X-Mailer') {
            $emailParams['headers'][$index] = 'swiftmailer';
        }
    }
    return $emailParams;
});
 

twisted1919

Administrator
Staff member
Right because it's too early for this header...
Try this:
PHP:
Yii::app()->hooks->addFilter('mailer_after_create_message_instance', function($message, $params, $mailer) {
    // make sure we get the right mailer and not phpmailer...
    if (!($mailer instanceof MailerSwiftMailer) || !($message instanceof Swift_Message)) {
        return $message;
    }
    // remove the header, it's been added before...
    $message->getHeaders()->remove(sprintf('%sMailer', Yii::app()->params['email.custom.header.prefix']));

    // add the new header with the value we want
    $message->getHeaders()->addTextHeader(sprintf('%sMailer', Yii::app()->params['email.custom.header.prefix']), 'SwiftMailer');

    // return the message in the end
    return $message;
});
in apps/init-custom.php as you properly noted before.
 

nemesis82

Active Member
maybe i've solved.
deleting and re-creating the same file now the fix works again. Rewriting or changing some value not solve the issue, deleting and recreting it seems do the job.
i'll update you .
@twisted1919 @laurentiu thx
 
Top