previousMail_Mime::addAttachment() (Previous) (Next) Mail_Mime::get()next

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

Mail_Mime::addHTMLImage()

Mail_Mime::addHTMLImage() – Ajout d'une image au message

Synopsis

require_once 'Mail/mime.php';

boolean addHTMLImage ( string $data , string $c_type = 'application/octet-stream' , string $name = '' , boolean $isfile = true )

Description

Si vous devez envoyer un message HTML avec des images inclues, employez cette fonction pour ajouter l'image.

Parameter

  • string $file - le nom du fichier contenant l'image ou les données de l'image elles-même

  • string $c_type - le type de contenu de l'image ou du fichier.

  • string $name - le nom du fichier de l'image. A n'utiliser, qu si $file contient les données de l'image.

  • - Vrai si $file est un nom de fichier.

Return value

boolean - Returns TRUE on success, PEAR_Error on failure.

Throws

Possible PEAR_Error values
Code erreur Message d'erreur affiché Message d'erreur Cause Solution
NULL " File is not readable file_name " " Le fichier file_name n'est pas accessible en lecture. " Le fichier n'a pas été trouvé ou le script n'a pas assez de droits système pour accéder au fichier. Vérifiez le nom et le chemin du fichier. Vérifiez l'utilisateur et les permissions sur ce fichier.
NULL "Could not open file_name " "Ouverture de file_name impossible" Le fichier est déjà ouvert et verrouillé par une autre application. Dans la plupart des cas c'est un programme qui a ouvert le fichier en écriture. addHTMLImage() ne place aucun verrou sur les fichiers qu'il traîte. Ce problème n'est donc pas provoqué par d'éventuels appels concurrent de cette fonction.

Note

This function can not be called statically.

previousMail_Mime::addAttachment() (Previous) (Next) Mail_Mime::get()next

Download Documentation Last updated: Sun, 18 Oct 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: erwin@darwine.nl
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().

So:
WRONG:
$mail->setHTMLBody('<html><body><img src="myImg.gif"> <p>You don't see this image.</p></body></html>');
$mail->addHTMLImage('./images/myImg.gif', 'image/gif');

RIGHT:
$mail->setHTMLBody('<html><body><img src="images/myImg.gif"> <p>You don't see this image.</p></body></html>');
$mail->addHTMLImage('images/myImg.gif', 'image/gif');

This was a little confusing for me since I expected the addHTMLImage() to simply fetch the image from source, but appearantly it is also using that same path in the actual source of the email.

Great package!
Regards,
Erwin
Note by: Lawrence
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.:

----
$mime->addHTMLImage("../../img_dir/butterfly.gif");
----
<img src="../../img_dir/butterfly.gif">
----

If you pass a full path to addHTMLImage(), you need to use the full path in your HTML:

----
$mime->addHTMLImage("/home/lawrence/img_dir/butterfly.gif");
----
<img src="/home/lawrence/img_dir/butterfly.gif">
----
Note by: lech.jonczyk@gmail.com
This is how it worked for me:

In the code:

$mime = new Mail_mime($crlf);
$mime->addHTMLimage('mail_templates/img/bg.png', 'image/png');

In the html part of mail body:

<img src="mail_templates/img/bg.png"/>

Cheers
Note by: nwalter@easymailing.eu
How can i get Mime_mail to replace my HTML-Image-Tags by CID strings?
Note by: Joseph@ppool.de
Post #1 is wrong for me it is exactly the opposit:
You must not use an absolute system path but must flatten the file name in the SRC="" tag to contain no folder names or slashes.
Note by: jlang
If you want to add inline images and reference them in your HTML you must use the fully qualified system path.

That means year image should look like this:
<img src="/home/public_html/image.gif">
not
<img src="image.gif">

Mail_Mime will replace your src with the appropriate CID value
Note by: info@roxlu.com
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