Fix option moreinheader not correctly supported with smtps

This commit is contained in:
Laurent Destailleur 2016-12-20 12:38:24 +01:00
parent 3c79f3acb5
commit 0ef963604f
2 changed files with 43 additions and 13 deletions

View File

@ -54,6 +54,7 @@ class CMailFile
var $deliveryreceipt; var $deliveryreceipt;
var $eol; var $eol;
var $eol2;
var $atleastonefile=0; var $atleastonefile=0;
var $error=''; var $error='';
@ -103,7 +104,7 @@ class CMailFile
* @param string $errors_to Email for errors-to * @param string $errors_to Email for errors-to
* @param string $css Css option * @param string $css Css option
* @param string $trackid Tracking string * @param string $trackid Tracking string
* @param string $moreinheader More in header (for phpmail only for the moment) * @param string $moreinheader More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'phpmail' and 'smtps' for the moment)
*/ */
function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='',$trackid='',$moreinheader='') function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='',$trackid='',$moreinheader='')
{ {
@ -117,6 +118,7 @@ class CMailFile
{ {
$this->eol="\n"; $this->eol="\n";
$this->eol2="\n"; $this->eol2="\n";
$moreinheader = str_replace("\r\n","\n",$moreinheader);
} }
// On defini mixed_boundary // On defini mixed_boundary
@ -209,7 +211,7 @@ class CMailFile
$this->deliveryreceipt = $deliveryreceipt; $this->deliveryreceipt = $deliveryreceipt;
$this->trackid = $trackid; $this->trackid = $trackid;
$smtp_headers = $this->write_smtpheaders(); $smtp_headers = $this->write_smtpheaders();
if (! empty($moreinheader)) $smtp_headers.=$moreinheader; if (! empty($moreinheader)) $smtp_headers.=$moreinheader; // $moreinheader contains the \r\n
// Define mime_headers // Define mime_headers
$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
@ -270,6 +272,7 @@ class CMailFile
$smtps->setFrom($this->getValidAddress($from,0,1)); $smtps->setFrom($this->getValidAddress($from,0,1));
$smtps->setTrackId($trackid); $smtps->setTrackId($trackid);
$smtps->setReplyTo($this->getValidAddress($from,0,1)); // Set property with this->smtps->setReplyTo after constructor if you want to use another value than the From $smtps->setReplyTo($this->getValidAddress($from,0,1)); // Set property with this->smtps->setReplyTo after constructor if you want to use another value than the From
if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
if (! empty($this->html)) if (! empty($this->html))
{ {
@ -324,6 +327,7 @@ class CMailFile
$this->phpmailer->SetFrom($this->getValidAddress($from,0,1)); $this->phpmailer->SetFrom($this->getValidAddress($from,0,1));
$this->phpmailer->SetReplyTo($this->getValidAddress($from,0,1)); // Set property with this->phpmailer->setReplyTo after constructor if you want to use another value than the From $this->phpmailer->SetReplyTo($this->getValidAddress($from,0,1)); // Set property with this->phpmailer->setReplyTo after constructor if you want to use another value than the From
// TODO Add trackid into smtp header // TODO Add trackid into smtp header
// TODO if (! empty($moreinheader)) ...
if (! empty($this->html)) if (! empty($this->html))
{ {
@ -377,6 +381,7 @@ class CMailFile
$msgid = $headers->get('Message-ID'); $msgid = $headers->get('Message-ID');
$msgid->setId($headerID); $msgid->setId($headerID);
$headers->addIdHeader('References', $headerID); $headers->addIdHeader('References', $headerID);
// TODO if (! empty($moreinheader)) ...
// Give the message a subject // Give the message a subject
$this->message->setSubject($this->encodetorfc2822($subject)); $this->message->setSubject($this->encodetorfc2822($subject));

View File

@ -225,7 +225,8 @@ class SMTPs
var $log = ''; var $log = '';
var $_errorsTo = ''; var $_errorsTo = '';
var $_deliveryReceipt = 0; var $_deliveryReceipt = 0;
var $_trackId = ''; var $_trackId = '';
var $_moreInHeader = '';
/** /**
@ -261,15 +262,36 @@ class SMTPs
} }
/** /**
* Set moreInHeader
*
* @param string $_val Value
* @return void
*/
function setMoreInHeader($_val = '')
{
$this->_moreinheader = $_val;
}
/**
* get trackid * get trackid
* *
* @return string Delivery receipt * @return string Track id
*/ */
function getTrackId() function getTrackId()
{ {
return $this->_trackId; return $this->_trackId;
} }
/**
* get moreInHeader
*
* @return string moreInHeader
*/
function getMoreInHeader()
{
return $this->_moreinheader;
}
/** /**
* Set errors to * Set errors to
* *
@ -1213,6 +1235,8 @@ class SMTPs
{ {
$_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
} }
if ( $this->getMoreInHeader() )
$_header .= $this->getMoreInHeader(); // Value must include the "\r\n";
//$_header .= //$_header .=
// 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
@ -1227,14 +1251,15 @@ class SMTPs
// DOL_CHANGE LDR // DOL_CHANGE LDR
if ( $this->getDeliveryReceipt() ) if ( $this->getDeliveryReceipt() )
$_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
if ( $this->getErrorsTo() ) if ( $this->getErrorsTo() )
$_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
if ( $this->getReplyTo() ) if ( $this->getReplyTo() )
$_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
$_header .= 'Mime-Version: 1.0' . "\r\n";
$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"
. 'Mime-Version: 1.0' . "\r\n";
return $_header; return $_header;
} }