Synopsis

Description

If sending an HTML message with embedded images, use this function to add the
image.

Parameter

string $file - The image file name or the image
data itself

string $c_type - The content type of the image
or file.

string $name - The filename of the image. Only
used, if $file contains the image data.

boolean $isfile - Whether $file
is a filename or not.

string $content_id - The Content-ID value to use
for the embedded image. A NULL value will generate a suitably unique Content-ID.
When referencing the embedded image with an <img> tag, set
the "src" attribute to be "cid:whatever", where
"whatever" is the Content-ID.

Return value

boolean - Returns TRUE on success,
PEAR_Error on failure.

Throws

Possible PEAR_Error values

Error code

Error message

Reason

Solution

NULL

"File is not readable file_name"

The file was not found or the script has not enough rights to access the
file.

Check the file name and path. Check user and file permissions.

NULL

"Could not open file_name"

The file is already opened and exclusivly locked by another application.

In the most cases a programm opens the file for writing.
addHTMLImage() does no file locking, so this problem is
not caused by competitve callings of this function.

I recommend this function be renamed to addInlineAttachment() since it doesn't specifically apply to images. You can also use this to embed style sheets etc. So far i've only seen Thunderbird support embedded style sheets but i hope more mail clients start to.

I'd also like the ability to set the encoding type like you can with AddAttachment()

I had troubles using INLINE IMAGES in HTML mail.
It seems a lot of people were confused (judging by the many posts in all kind of fora)
I couldn't use inline images untill I found out that the image must use the same path in the HTML as in the functioncall addhtmlimage().

Re: Joseph's and jlang's notes about the filename -- I believe you just have to use the *same* full filename in both your HTML and in the call to addHTMLImage(). If you pass a relative path to addHTMLImage(), you need to use the relative path as the URL in the HTML. I.e.:

I found out that when you are adding html images inline you need to make sure what kind of transport you use. When using the default "mail" function my images weren't shown in some clients. When I switched to "smtp" everything worked perfectly