Add: build style css in mail
This commit is contained in:
parent
59920dc63a
commit
842d240980
@ -288,6 +288,11 @@ if ($_POST["action"] == 'send' && ! $_POST["cancel"])
|
|||||||
$arr_file = array();
|
$arr_file = array();
|
||||||
$arr_mime = array();
|
$arr_mime = array();
|
||||||
$arr_name = array();
|
$arr_name = array();
|
||||||
|
$arr_css = array();
|
||||||
|
|
||||||
|
// Ajout CSS
|
||||||
|
if (!empty($mil->bgcolor)) $arr_css['bgcolor'] = $mil->bgcolor;
|
||||||
|
if (!empty($mil->bgimage)) $arr_css['bgimage'] = $mil->bgimage;
|
||||||
|
|
||||||
// Le message est-il en html
|
// Le message est-il en html
|
||||||
$msgishtml=-1; // Inconnu par defaut
|
$msgishtml=-1; // Inconnu par defaut
|
||||||
@ -298,8 +303,7 @@ if ($_POST["action"] == 'send' && ! $_POST["cancel"])
|
|||||||
$mil->body=make_substitutions($mil->body,$substitutionarrayfortest);
|
$mil->body=make_substitutions($mil->body,$substitutionarrayfortest);
|
||||||
|
|
||||||
$mailfile = new CMailFile($mil->sujet,$mil->sendto,$mil->email_from,$mil->body,
|
$mailfile = new CMailFile($mil->sujet,$mil->sendto,$mil->email_from,$mil->body,
|
||||||
$arr_file,$arr_mime,$arr_name,
|
$arr_file,$arr_mime,$arr_name,'', '', 0, $msgishtml,'',$arr_css);
|
||||||
'', '', 0, $msgishtml);
|
|
||||||
|
|
||||||
$result=$mailfile->sendfile();
|
$result=$mailfile->sendfile();
|
||||||
if ($result)
|
if ($result)
|
||||||
|
|||||||
@ -60,6 +60,10 @@ class CMailFile
|
|||||||
var $sName;
|
var $sName;
|
||||||
var $sEmail;
|
var $sEmail;
|
||||||
|
|
||||||
|
//CSS
|
||||||
|
var $css;
|
||||||
|
var $styleCSS;
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
var $html;
|
var $html;
|
||||||
var $image_boundary;
|
var $image_boundary;
|
||||||
@ -87,12 +91,14 @@ class CMailFile
|
|||||||
* \param mimefilename_list List of attached file name in message
|
* \param mimefilename_list List of attached file name in message
|
||||||
* \param addr_cc Email cc
|
* \param addr_cc Email cc
|
||||||
* \param addr_bcc Email bcc
|
* \param addr_bcc Email bcc
|
||||||
* \param deliveryreceipt Ask a delivery receipt
|
* \param deliveryreceipt Ask a delivery receipt
|
||||||
* \param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
|
* \param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
|
||||||
|
* \param error_to Email errors
|
||||||
|
* \param css Css option
|
||||||
*/
|
*/
|
||||||
function CMailFile($subject,$to,$from,$msg,
|
function CMailFile($subject,$to,$from,$msg,
|
||||||
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
|
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
|
||||||
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='')
|
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='')
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
@ -271,6 +277,12 @@ class CMailFile
|
|||||||
{
|
{
|
||||||
if (! empty($this->html))
|
if (! empty($this->html))
|
||||||
{
|
{
|
||||||
|
if (!empty($css))
|
||||||
|
{
|
||||||
|
$this->css = $css;
|
||||||
|
$this->styleCSS = $this->buildCSS();
|
||||||
|
}
|
||||||
|
|
||||||
$msg = $this->html;
|
$msg = $this->html;
|
||||||
$msg = $this->checkIfHTML($msg);
|
$msg = $this->checkIfHTML($msg);
|
||||||
|
|
||||||
@ -315,9 +327,13 @@ class CMailFile
|
|||||||
$smtps->setTO($this->getValidAddress($to,2));
|
$smtps->setTO($this->getValidAddress($to,2));
|
||||||
$smtps->setFrom($from);
|
$smtps->setFrom($from);
|
||||||
|
|
||||||
//if ($this->atleastoneimage) $msg = $this->html;
|
|
||||||
if (! empty($this->html))
|
if (! empty($this->html))
|
||||||
{
|
{
|
||||||
|
if (!empty($css))
|
||||||
|
{
|
||||||
|
$this->css = $css;
|
||||||
|
$this->styleCSS = $this->buildCSS();
|
||||||
|
}
|
||||||
$msg = $this->html;
|
$msg = $this->html;
|
||||||
$msg = $this->checkIfHTML($msg);
|
$msg = $this->checkIfHTML($msg);
|
||||||
}
|
}
|
||||||
@ -639,8 +655,6 @@ class CMailFile
|
|||||||
|
|
||||||
$out='';
|
$out='';
|
||||||
|
|
||||||
// if ($this->atleastonefile || $this->atleastoneimage)
|
|
||||||
// {
|
|
||||||
if ($this->msgishtml)
|
if ($this->msgishtml)
|
||||||
{
|
{
|
||||||
$out.= "--" . $this->mime_boundary . $this->eol;
|
$out.= "--" . $this->mime_boundary . $this->eol;
|
||||||
@ -652,39 +666,23 @@ class CMailFile
|
|||||||
$out.= "Content-Type: text/plain; charset=\"".$conf->file->character_set_client."\"".$this->eol;
|
$out.= "Content-Type: text/plain; charset=\"".$conf->file->character_set_client."\"".$this->eol;
|
||||||
}
|
}
|
||||||
$out.= $this->eol;
|
$out.= $this->eol;
|
||||||
// }
|
|
||||||
if ($this->msgishtml)
|
if ($this->msgishtml)
|
||||||
{
|
{
|
||||||
// Check if html header already in message
|
// Check if html header already in message
|
||||||
$strContent = $this->checkIfHTML($msgtext);
|
$strContent = $this->checkIfHTML($msgtext);
|
||||||
|
|
||||||
/*if ($this->atleastonefile || $this->atleastoneimage)
|
|
||||||
{
|
|
||||||
if ($this->atleastonefile && $this->atleastoneimage)
|
|
||||||
{
|
|
||||||
$out.= $this->eol . "--" . $this->related_boundary . $this->eol;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$out.= $this->eol . "--" . $this->mime_boundary . $this->eol;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$strContent.= $msgtext;
|
$strContent.= $msgtext;
|
||||||
/* if ($this->atleastonefile || $this->atleastoneimage)
|
|
||||||
{
|
|
||||||
$out.= $this->eol . "--" . $this->mime_boundary . $this->eol;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make RFC821 Compliant, replace bare linefeeds
|
// Make RFC821 Compliant, replace bare linefeeds
|
||||||
$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent );
|
$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent );
|
||||||
|
|
||||||
$strContent = rtrim(wordwrap($strContent));
|
$strContent = rtrim(wordwrap($strContent));
|
||||||
|
|
||||||
$out.=$strContent.$this->eol;
|
$out.=$strContent.$this->eol;
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
@ -695,12 +693,12 @@ class CMailFile
|
|||||||
* @param unknown_type $msg
|
* @param unknown_type $msg
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function checkIfHTML($msg,$css='')
|
function checkIfHTML($msg)
|
||||||
{
|
{
|
||||||
if (!eregi('^[ \t]*<html',$msg))
|
if (!eregi('^[ \t]*<html',$msg))
|
||||||
{
|
{
|
||||||
$out = "<html><head><title></title>";
|
$out = "<html><head><title></title>";
|
||||||
if (!empty($css)) $out.= $css;
|
if (!empty($this->styleCSS)) $out.= $this->styleCSS;
|
||||||
$out.= "</head><body>";
|
$out.= "</head><body>";
|
||||||
$out.= $msg;
|
$out.= $msg;
|
||||||
$out.= "</body></html>";
|
$out.= "</body></html>";
|
||||||
@ -716,17 +714,29 @@ class CMailFile
|
|||||||
/**
|
/**
|
||||||
* Build a css style
|
* Build a css style
|
||||||
*
|
*
|
||||||
* @param $value
|
|
||||||
* @return css
|
* @return css
|
||||||
*/
|
*/
|
||||||
function buildCSS($value)
|
function buildCSS()
|
||||||
{
|
{
|
||||||
// Todo: finir la construction
|
$out = '';
|
||||||
$out = '<style type="text/css">'
|
|
||||||
. 'body {'
|
if (!empty($this->css))
|
||||||
. ' background-image: url("cid:'.$bg.'");'
|
{
|
||||||
. '}'
|
$out.= '<style type="text/css">';
|
||||||
. '</style>';
|
$out.= 'body {';
|
||||||
|
|
||||||
|
if ($this->css['bgcolor'])
|
||||||
|
{
|
||||||
|
$out.= ' background-color: '.$this->css['bgcolor'].';';
|
||||||
|
}
|
||||||
|
if ($this->css['bgimage'])
|
||||||
|
{
|
||||||
|
// Todo: récupérer cid
|
||||||
|
$out.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
|
||||||
|
}
|
||||||
|
$out.= '}';
|
||||||
|
$out.= '</style>';
|
||||||
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user