public function PHPMailer::encodeString

5.x PHPMailer.php public PHPMailer::encodeString($str, $encoding = self::ENCODING_BASE64)

Encode a string in requested format. Returns an empty string on failure.

Parameters

string $str The text to encode:

string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable':

Return value

string

Throws

Exception

3 calls to PHPMailer::encodeString()
PHPMailer::attachAll in inc/PHPMailer/src/PHPMailer.php
Attach all file, string, and binary attachments to the message. Returns an empty string on failure.
PHPMailer::createBody in inc/PHPMailer/src/PHPMailer.php
Assemble the message body. Returns an empty string on failure.
PHPMailer::encodeFile in inc/PHPMailer/src/PHPMailer.php
Encode a file attachment in requested format. Returns an empty string on failure.

File

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

Class

PHPMailer
PHPMailer - PHP email creation and transport class.

Namespace

PHPMailer\PHPMailer

Code

public function encodeString($str, $encoding = self::ENCODING_BASE64) 
 {
  $encoded = '';
  switch (strtolower($encoding)) {
    case static::ENCODING_BASE64:
      $encoded = chunk_split(
      base64_encode($str), 
      static::STD_LINE_LENGTH, 
      static::$LE
      );
      break;
    case static::ENCODING_7BIT:
    case static::ENCODING_8BIT:
      $encoded = static::normalizeBreaks($str);
      // Make sure it ends with a line break
      if (substr($encoded, -(strlen(static::$LE))) != static::$LE) {
        $encoded .= static::$LE;
      }
      break;
    case static::ENCODING_BINARY:
      $encoded = $str;
      break;
    case static::ENCODING_QUOTED_PRINTABLE:
      $encoded = $this->encodeQP($str);
      break;
    default:
      $this->setError($this->lang('encoding') . $encoding);
      if ($this->exceptions) {
        throw new Exception($this->lang('encoding') . $encoding);
      }
      break;
  }

  return $encoded;
}