PHPMailer\PHPMailer

PHPMailer::replaceCustomHeader()publicWP 1.0

Replace a custom header. $name value can be overloaded to contain both header name and value (name:value).

Method of the class: PHPMailer{}

No Hooks.

Return

true|false. True if a header was replaced successfully

Usage

$PHPMailer = new PHPMailer();
$PHPMailer->replaceCustomHeader( $name, $value );
$name(string) (required)
Custom header name
$value(string|null)
Header value
Default: null

PHPMailer::replaceCustomHeader() code WP 6.5.4

public function replaceCustomHeader($name, $value = null)
{
    if (null === $value && strpos($name, ':') !== false) {
        //Value passed in as name:value
        list($name, $value) = explode(':', $name, 2);
    }
    $name = trim($name);
    $value = (null === $value) ? '' : trim($value);

    $replaced = false;
    foreach ($this->CustomHeader as $k => $pair) {
        if ($pair[0] == $name) {
            if ($replaced) {
                unset($this->CustomHeader[$k]);
                continue;
            }
            if (strpbrk($name . $value, "\r\n") !== false) {
                if ($this->exceptions) {
                    throw new Exception($this->lang('invalid_header'));
                }

                return false;
            }
            $this->CustomHeader[$k] = [$name, $value];
            $replaced = true;
        }
    }

    return true;
}