NEW Can set the reply-to into email sent

This commit is contained in:
Laurent Destailleur 2018-02-28 19:09:05 +01:00
parent 3c903675f2
commit de9f1aab0f

View File

@ -109,13 +109,16 @@ class CMailFile
* @param string $trackid Tracking string (contains type and id of related element)
* @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)
* @param string $sendcontext 'standard', 'emailing', ... (used to define with sending mode and parameters to use)
* @param string $replyto Reply-to email (will be set to same value than From by default if not provided)
*/
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='',$sendcontext='standard')
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='',$sendcontext='standard',$replyto='')
{
global $conf, $dolibarr_main_data_root;
$this->sendcontext = $sendcontext;
if (empty($replyto)) $replyto=$from;
// Define this->sendmode
$this->sendmode = '';
if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
@ -234,7 +237,7 @@ class CMailFile
// Define smtp_headers
$this->subject = $subject;
$this->addr_from = $from;
$this->reply_to = $from; // Set this property after constructor if you want to use another value
$this->reply_to = $replyto;
$this->errors_to = $errors_to;
$this->addr_to = $to;
$this->addr_cc = $addr_cc;
@ -293,7 +296,7 @@ class CMailFile
$smtps->setTO($this->getValidAddress($to,0,1));
$smtps->setFrom($this->getValidAddress($from,0,1));
$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($replyto,0,1));
if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
@ -348,7 +351,7 @@ class CMailFile
$this->phpmailer->Subject($this->encodetorfc2822($subject));
$this->phpmailer->setTO($this->getValidAddress($to,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($replyto,0,1));
// TODO Add trackid into smtp header
// TODO if (! empty($moreinheader)) ...
@ -418,7 +421,7 @@ class CMailFile
// Set the To addresses with an associative array
if (! empty($to)) $this->message->setTo($this->getArrayAddress($to));
if (! empty($from)) $this->message->SetReplyTo($this->getArrayAddress($from));
if (! empty($replyto)) $this->message->SetReplyTo($this->getArrayAddress($replyto));
$this->message->setCharSet($conf->file->character_set_client);
@ -563,7 +566,7 @@ class CMailFile
$keyfortls ='MAIN_MAIL_EMAIL_TLS_EMAILING';
$keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
}
if(!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) {
$this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
$this->addr_cc = '';
@ -590,13 +593,22 @@ class CMailFile
if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
if (! empty($conf->global->$keyforsmtpport)) ini_set('smtp_port',$conf->global->$keyforsmtpport);
$res=true;
if ($res && ! $this->subject)
{
$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
$res=false;
}
$dest=$this->getValidAddress($this->addr_to,2);
if (! $dest)
if ($res && ! $dest)
{
$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
$res=false;
}
else
if ($res)
{
$additionnalparam = ''; // By default
if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
@ -689,14 +701,14 @@ class CMailFile
$res=true;
$from=$this->smtps->getFrom('org');
if (! $from)
if ($res && ! $from)
{
$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
$res=false;
}
$dest=$this->smtps->getTo();
if (! $dest)
if ($res && ! $dest)
{
$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);