examine and change php.ini mail.add_x_header value

Discussion in 'Programming/Scripts' started by Taleman, Sep 11, 2020.

  1. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    I needed to change php.ini value mail.add_x_header from Off to On. However, it was in 22 php.ini files on my host, so I wrote two scripts: first one to examine the situation and another to change the value.
    Situation was discussed in forum thread https://www.howtoforge.com/community/threads/how-to-add-mail-add_x_header-for-all-php-scripts.85050/
    Scripts follow:
    # cat examine-php-mail-add-x-header.sh
    #! /bin/bash
    echo "Find the php.ini files with add_x_header line:"
    find /etc/php -name php.ini -exec grep mail.add_x_header --with-filename {} \;
    echo "Check if all of them have that line:"
    echo "find /etc/php -name php.ini | wc -l"
    find /etc/php -name php.ini | wc -l
    echo "find /etc/php -name php.ini -exec grep mail.add_x_header --with-filename {} \; | wc -l"
    find /etc/php -name php.ini -exec grep mail.add_x_header --with-filename {} \; | wc -l
    echo "If numbers match, all php.ini files had that line"
    # cat change-php-mail-add-x-header.sh
    #! /bin/bash
    echo "Find the php.ini files with add_x_header line and change Off to On"
    find /etc/php -name php.ini -exec sed -i 's/mail.add_x_header = Off/mail.add_x_header = On/' {} \;
    ganewbie likes this.

Share This Page