PHPMailer\PHPMailer

PHPMailer::addEmbeddedImagepublicWP 1.0

Add an embedded (inline) attachment from a file. This can include images, sounds, and just about any other document type. These differ from 'regular' attachments in that they are intended to be displayed inline with the message, not just attached for download. This is used in HTML messages that embed the images the HTML refers to using the $cid value in img tags, for example <img src="cid:mylogo">. Never use a user-supplied path to a file!

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

Хуков нет.

Возвращает

true|false. True on successfully adding an attachment

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

$PHPMailer = new PHPMailer();
$PHPMailer->addEmbeddedImage( $path, $cid, $name, $encoding, $type, $disposition );
$path(строка) (обязательный)
Path to the attachment.
$cid(строка) (обязательный)
Content ID of the attachment; Use this to reference the content when using an embedded image in HTML.
$name(строка)
Overrides the attachment filename.
По умолчанию: ''
$encoding(строка)
File encoding (see $Encoding) defaults to base64.
По умолчанию: self::ENCODING_BASE64
$type(строка)
File MIME type (by default mapped from the $path filename's extension).
По умолчанию: ''
$disposition(строка)
Disposition to use: inline (default) or attachment (unlikely you want this – {@see addAttachment()} instead).
По умолчанию: 'inline'

Код PHPMailer::addEmbeddedImage() WP 6.9.1

public function addEmbeddedImage(
    $path,
    $cid,
    $name = '',
    $encoding = self::ENCODING_BASE64,
    $type = '',
    $disposition = 'inline'
) {
    try {
        if (!static::fileIsAccessible($path)) {
            throw new Exception(self::lang('file_access') . $path, self::STOP_CONTINUE);
        }

        //If a MIME type is not specified, try to work it out from the file name
        if ('' === $type) {
            $type = static::filenameToType($path);
        }

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

        $filename = (string) static::mb_pathinfo($path, PATHINFO_BASENAME);
        if ('' === $name) {
            $name = $filename;
        }

        //Append to $attachment array
        $this->attachment[] = [
            0 => $path,
            1 => $filename,
            2 => $name,
            3 => $encoding,
            4 => $type,
            5 => false, //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;
}