Programmer's Reference Guide
| Courriel HTML |
Fichiers joints
Des fichiers peuvent-être attachés à un courriel en utilisant la méthode createAttachment(). Le comportement par défaut de Zend_Mail est de définir que le fichier joint est un objet binaire (application/octet-stream), qui devra être transféré avec un encodage de type base64, et est définit comme une pièce jointe. Ce comportement peut être redéfinit en passant plus de paramètres à createAttachment() :
Exemple #1 Courriel avec fichiers joints
- $mail = new Zend_Mail();
- // construction du message
- $mail->createAttachment($uneChaineBinaire);
- $mail->createAttachment($monImage,
- 'image/gif',
- Zend_Mime::DISPOSITION_INLINE,
- Zend_Mime::ENCODING_BASE64);
Si vous voulez contrôler la partie MIME générée pour un fichier joint, vous pouvez utiliser la valeur retournée de createAttachment() pour modifier ses attributs. La méthodes createAttachment() retourne un objet de type Zend_Mime_Part :
- $mail = new Zend_Mail();
- $at = $mail->createAttachment($monImage);
- $at->type = 'image/gif';
- $at->disposition = Zend_Mime::DISPOSITION_INLINE;
- $at->encoding = Zend_Mime::ENCODING_BASE64;
- $at->filename = 'test.gif';
- $mail->send();
Une façon alternative est de créer une instance de Zend_Mime_Part et de l'ajouter avec la méthode addAttachment() :
- $mail = new Zend_Mail();
- $at = new Zend_Mime_Part($monImage);
- $at->type = 'image/gif';
- $at->disposition = Zend_Mime::DISPOSITION_INLINE;
- $at->encoding = Zend_Mime::ENCODING_BASE64;
- $at->filename = 'test.gif';
- $mail->addAttachment($at);
- $mail->send();
| Courriel HTML |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.
Select a Version
Languages Available
Components
Search the Manual
Navigation
- Guide de référence du programmeur
- Guide de référence du programmeur
- Guide de référence Zend Framework
- Zend_Mail
- Introduction
- Envoyer des courriels en utilisant SMTP
- Envoyer plusieurs courriels par connexion SMTP
- Utiliser différents transports
- Courriel HTML
- Fichiers joints
- Ajouter des destinataires
- Contrôler les limites MIME
- En-têtes additionnels
- Jeux de caractères
- Encodage
- Authentification SMTP
- Sécuriser les transports SMTP
- Lire des courriels

Comments
$myImage should be a binary string. A binary string can be obtained with file_get_contents() method. Here is an example:
$myImage = file_get_contents('logo.png');
$at = $mail->createAttachment($myImage);
$at->filename = 'logo.png';
$myImage should be a binary string. A binary string can be obtained with file_get_contents() method. Here is an example:
$myImage = file_get_contents('logo.png');
$at = $mail->createAttachment($myImage);
$at->filename = 'logo.png';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
and $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
so in Thunderbird html mail with embedded images are not displayed.
According to this art. http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html and some wiki art., for embedded images, Zend_Mime::DISPOSITION_INLINE must place image to be part of text/html related MIME boundary, wich is not case.
Is It a Bug or ?
Thank You
khi tôi làm thế này mà vẫn khong send được mail không biết là có lỗi gì hoặc sai ở đâu ?
when I do this and still not send the mail does not know what error or wrong?
$at = new Zend_Mime_Part('/hoc/email/trunk/public/upload/uploads/GsNJNwuI-UM.gif');
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = '/hoc/email/trunk/public/upload/uploads/GsNJNwuI-UM.gif';
$mail->addAttachment($at);
help me
Hi All
I have found a method and all references. The following is an example
$myImage = file_get_contents('upload/uploads/avatar.jpg');
$at = new Zend_Mime_Part($myImage);
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = 'avatar.jpg';
$mail->addAttachment($at);