PHPMailer\PHPMailer

PHPMailer::addStringEmbeddedImagepublicWP 1.0

Add an embedded stringified attachment. This can include images, sounds, and just about any other document type. If your filename doesn't contain an extension, be sure to set the $type to an appropriate MIME type.

Method of the class: PHPMailer{}

No Hooks.

Returns

true|false. True on successfully adding an attachment

Usage

$PHPMailer = new PHPMailer();
$PHPMailer->addStringEmbeddedImage( $string, $cid, $name, $encoding, $type, $disposition );
$string(string) (required)
The attachment binary data.
$cid(string) (required)
Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
$name(string)
A filename for the attachment. If this contains an extension, PHPMailer will attempt to set a MIME type for the attachment. For example 'file.jpg' would get an 'image/jpeg' MIME type.
Default: ''
$encoding(string)
File encoding (see $Encoding).
Default: 'base64'
$type(string)
MIME type - will be used in preference to any automatically derived type.
Default: ''
$disposition(string)
Disposition to use.
Default: 'inline'

PHPMailer::addStringEmbeddedImage() code WP 6.8.1

public function addStringEmbeddedImage(
    $string,
    $cid,
    $name = '',
    $encoding = self::ENCODING_BASE64,
    $type = '',
    $disposition = 'inline'
) {
    try {
        //If a MIME type is not specified, try to work it out from the name
        if ('' === $type && !empty($name)) {
            $type = static::filenameToType($name);
        }

        if (!$this->validateEncoding($encoding)) {
            throw new Exception($this->lang('encoding') . $encoding);
        }

        //Append to $attachment array
        $this->attachment[] = [
            0 => $string,
            1 => $name,
            2 => $name,
            3 => $encoding,
            4 => $type,
            5 => true, //isStringAttachment
            6 => $disposition,
            7 => $cid,
        ];
    } catch (Exception $exc) {
        $this->setError($exc->getMessage());
        $this->edebug($exc->getMessage());
        if ($this->exceptions) {
            throw $exc;
        }

        return false;
    }

    return true;
}