PHPMailer\PHPMailer

PHPMailer::generateId()protectedWP 1.0

Create a unique ID to use for boundaries.

Метод класса: PHPMailer{}

Хуков нет.

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->generateId();

Код PHPMailer::generateId() WP 6.5.2

protected function generateId()
{
    $len = 32; //32 bytes = 256 bits
    $bytes = '';
    if (function_exists('random_bytes')) {
        try {
            $bytes = random_bytes($len);
        } catch (\Exception $e) {
            //Do nothing
        }
    } elseif (function_exists('openssl_random_pseudo_bytes')) {
        /** @noinspection CryptographicallySecureRandomnessInspection */
        $bytes = openssl_random_pseudo_bytes($len);
    }
    if ($bytes === '') {
        //We failed to produce a proper random string, so make do.
        //Use a hash to force the length to the same as the other methods
        $bytes = hash('sha256', uniqid((string) mt_rand(), true), true);
    }

    //We don't care about messing up base64 format here, just want a random string
    return str_replace(['=', '+', '/'], '', base64_encode(hash('sha256', $bytes, true)));
}