protected function PHPMailer::generateId

5.x PHPMailer.php protected PHPMailer::generateId()

Create a unique ID to use for boundaries.

Return value

string

1 call to PHPMailer::generateId()
PHPMailer::createBody in inc/PHPMailer/src/PHPMailer.php
Assemble the message body. Returns an empty string on failure.

File

inc/PHPMailer/src/PHPMailer.php, line 2485

Class

PHPMailer
PHPMailer - PHP email creation and transport class.

Namespace

PHPMailer\PHPMailer

Code

protected function generateId() 
 {
  $len = 32; //32 bytes = 256 bits
  if (function_exists('random_bytes')) {
    $bytes = random_bytes($len);
  }
  elseif (function_exists('openssl_random_pseudo_bytes')) {
    $bytes = openssl_random_pseudo_bytes($len);
  }
  else {
    //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)));
}