Add: possibilité d'envoyer un fichier attaché avec du html contenant des images avec

la classe SMTPS
This commit is contained in:
Regis Houssin 2009-05-12 08:39:40 +00:00
parent f90cc7e225
commit a648e34b67

View File

@ -407,6 +407,9 @@ class SMTPs
*/ */
var $_smtpsBoundary = null; var $_smtpsBoundary = null;
// DOL_CHANGE LDR
var $_smtpsRelatedBoundary = null;
/** /**
* Property private int var $_transportType * Property private int var $_transportType
* *
@ -1939,6 +1942,10 @@ class SMTPs
// Generate a new Boundary string // Generate a new Boundary string
$this->_setBoundary(); $this->_setBoundary();
// DOL_CHANGE LDR
// Generate a new Related Boundary string
$this->_setRelatedBoundary();
// What type[s] of content do we have // What type[s] of content do we have
$_types = array_keys ( $this->_msgContent ); $_types = array_keys ( $this->_msgContent );
@ -1971,15 +1978,29 @@ class SMTPs
else if( $keyCount > 1 ) else if( $keyCount > 1 )
{ {
// DOL_CHANGE LDR // DOL_CHANGE LDR
$image=0;
$attachment=0;
foreach ($_types as $type) foreach ($_types as $type)
{ {
if ($type == 'image') if ($type == 'image')
{ {
$content = 'Content-Type: multipart/related;' . "\r\n"; $content = 'Content-Type: multipart/related;' . "\r\n"
. ' boundary="' . $this->_getBoundary() . '"' . "\r\n";
$image=1;
}
else if ($type == 'attachment' && $image)
{
$content = 'Content-Type: multipart/mixed;' . "\r\n"
. ' boundary="' . $this->_getBoundary() . '"' . "\r\n"
. "\r\n--" . $this->_getBoundary() . "\r\n"
. 'Content-Type: multipart/related;' . "\r\n"
. ' boundary="' . $this->_getRelatedBoundary() . '"' . "\r\n";
} }
else else
{ {
$content = 'Content-Type: multipart/mixed;' . "\r\n"; $content = 'Content-Type: multipart/mixed;' . "\r\n"
. ' boundary="' . $this->_getBoundary() . '"' . "\r\n";
$attachment=1;
} }
} }
// END DOL_CHANGE LDR // END DOL_CHANGE LDR
@ -1993,10 +2014,10 @@ class SMTPs
*/ */
// DOL_CHANGE LDR // DOL_CHANGE LDR
//$content = 'Content-Type: multipart/mixed;' . "\r\n" //$content = 'Content-Type: multipart/mixed;' . "\r\n"
$content = $content // . ' boundary="' . $this->_getBoundary() . '"' . "\r\n"
// . "\r\n"
$content .= "\r\n"
// END DOL_CHANGE LDR // END DOL_CHANGE LDR
. ' boundary="' . $this->_getBoundary() . '"' . "\r\n"
. "\r\n"
. 'This is a multi-part message in MIME format.' . "\r\n"; . 'This is a multi-part message in MIME format.' . "\r\n";
// Loop through message content array // Loop through message content array
@ -2027,9 +2048,16 @@ class SMTPs
// loop through all images // loop through all images
foreach ( $_content as $_image => $_data ) foreach ( $_content as $_image => $_data )
{ {
if ($attachment && $image)
{
$content .= "\r\n--" . $this->_getRelatedBoundary() . "\r\n";
}
else
{
$content .= "\r\n--" . $this->_getBoundary() . "\r\n";
}
$content .= "\r\n--" . $this->_getBoundary() . "\r\n" $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
. 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
. 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n"
. 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
. 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
@ -2039,15 +2067,26 @@ class SMTPs
$content .= "\r\n" $content .= "\r\n"
. $_data['data'] . "\r\n"; . $_data['data'] . "\r\n";
if ($attachment && $image) $content .= "\r\n--" . $this->_getRelatedBoundary() . '--' . "\r\n" ;
} }
} }
// END DOL_CHANGE LDR
else else
{ {
$content .= "\r\n--" . $this->_getBoundary() . "\r\n" if ($attachment && $image)
. 'Content-Type: ' . $_content['mimeType'] . '; ' {
$content .= "\r\n--" . $this->_getRelatedBoundary() . "\r\n";
}
else
{
$content .= "\r\n--" . $this->_getBoundary() . "\r\n";
}
//$content .= "\r\n--" . $this->_getBoundary() . "\r\n"
// . 'Content-Type: ' . $_content['mimeType'] . '; '
$content .= 'Content-Type: ' . $_content['mimeType'] . '; '
// END DOL_CHANGE LDR
. 'charset="' . $this->getCharSet() . '"'; . 'charset="' . $this->getCharSet() . '"';
//$content .= ( $type == 'html') ? '; name="HTML Part"' : ''; //$content .= ( $type == 'html') ? '; name="HTML Part"' : ''; // DOL_CHANGE LDR
$content .= "\r\n"; $content .= "\r\n";
$content .= 'Content-Transfer-Encoding: '; $content .= 'Content-Transfer-Encoding: ';
$content .= ( $type == 'html') ? 'quoted-printable' : $this->getTransEncodeType(); $content .= ( $type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
@ -2058,9 +2097,23 @@ class SMTPs
if ( $this->getMD5flag() ) if ( $this->getMD5flag() )
$content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
$content .= "\r\n" // DOL_CHANGE LDR
. $_content['data'] . "\r\n" //$content .= "\r\n"
. "\r\n--" . $this->_getBoundary() . "\r\n"; // . $_content['data'] . "\r\n"
// . "\r\n--" . $this->_getBoundary() . "\r\n";
if ($attachment && $image)
{
$content .= "\r\n"
. $_content['data'] . "\r\n"
. "\r\n--" . $this->_getRelatedBoundary() . "\r\n";
}
else
{
$content .= "\r\n"
. $_content['data'] . "\r\n"
. "\r\n--" . $this->_getBoundary() . "\r\n";
}
// END DOL_CHANGE LDR
} }
} }
@ -2367,6 +2420,12 @@ class SMTPs
$this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary"; $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
} }
// DOL_CHANGE LDR
function _setRelatedBoundary()
{
$this->_smtpsRelatedBoundary = "multipart_x." . time() . ".x_related_boundary";
}
/** /**
* Method private string _getBoundary( void ) * Method private string _getBoundary( void )
* *
@ -2389,6 +2448,12 @@ class SMTPs
return $this->_smtpsBoundary; return $this->_smtpsBoundary;
} }
// DOL_CHANGE LDR
function _getRelatedBoundary()
{
return $this->_smtpsRelatedBoundary;
}
// This function has been modified as provided // This function has been modified as provided
// by SirSir to allow multiline responses when // by SirSir to allow multiline responses when
// using SMTP Extensions // using SMTP Extensions
@ -2503,6 +2568,10 @@ class SMTPs
/** /**
* $Log$ * $Log$
* Revision 1.4 2009/05/12 08:39:40 hregis
* Add: possibilité d'envoyer un fichier attaché avec du html contenant des images avec
* la classe SMTPS
*
* Revision 1.3 2009/05/11 17:13:57 hregis * Revision 1.3 2009/05/11 17:13:57 hregis
* Add: possibilité d'uploader une image et de l'envoyer dans un mailing (finalisé et fonctionnel) * Add: possibilité d'uploader une image et de l'envoyer dans un mailing (finalisé et fonctionnel)
* Add: modification classe smtps.php pour l'envoi d'images * Add: modification classe smtps.php pour l'envoi d'images