diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php
index 2bd20a46be0..f32ad36dbe4 100644
--- a/htdocs/lib/CMailFile.class.php
+++ b/htdocs/lib/CMailFile.class.php
@@ -24,7 +24,7 @@
/**
* \file htdocs/lib/CMailFile.class.php
- * \brief Fichier de la classe permettant d'envoyer des mail avec attachements
+ * \brief File of class to send emails (with attachments or not)
* \version $Id$
* \author Dan Potter.
* \author Eric Seigne
@@ -33,7 +33,7 @@
/**
* \class CMailFile
- * \brief Classe d'envoi de mails et pieces jointes. Encapsule mail() avec d'eventuels attachements.
+ * \brief Class to send emails (with attachments or not)
* \remarks Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to);
* \remarks $mailfile->sendfile();
*/
@@ -165,6 +165,9 @@ class CMailFile
}
}
+ // Add autocopy to
+ if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
+
// Action according to choosed sending method
if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
{
@@ -334,7 +337,7 @@ class CMailFile
{
dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'), LOG_DEBUG);
- $bounce = '';
+ $bounce = ''; // By default
if ($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)
{
// le return-path dans les header ne fonctionne pas avec tous les MTA
@@ -347,7 +350,8 @@ class CMailFile
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
- $res = mail($dest,$this->encodetorfc2822($this->subject),$this->message,$this->headers, $bounce);
+ if (! empty($bounce)) $res = mail($dest,$this->encodetorfc2822($this->subject),$this->message,$this->headers, $bounce);
+ else $res = mail($dest,$this->encodetorfc2822($this->subject),$this->message,$this->headers);
if (! $res)
{
@@ -396,24 +400,25 @@ class CMailFile
{
$this->error="Failed to send mail to HOST=".$server.", PORT=".$conf->global->MAIN_MAIL_SMTP_PORT."
Recipient address '$dest' invalid";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
+ $res=false;
}
else
{
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
$result=$this->smtps->sendMsg();
//print $result;
+
+ if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
+
+ $result=$this->smtps->getErrors();
+ if (empty($this->error) && empty($result)) $res=true;
+ else
+ {
+ if (empty($this->error)) $this->error=$result;
+ dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
+ $res=false;
+ }
}
-
- if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
-
- $result=$this->smtps->getErrors();
- if (empty($this->error) && empty($result)) $res=true;
- else
- {
- if (empty($this->error)) $this->error=$result;
- $res=false;
- }
-
}
else
{
@@ -428,7 +433,7 @@ class CMailFile
else
{
$this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARN);
+ dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
}
error_reporting($errorlevel); // Reactive niveau erreur origine
@@ -470,7 +475,8 @@ class CMailFile
/**
- * Ecrit le mail dans un fichier. Utilisation pour le debuggage.
+ * Write content of a SMTP request into a dump file (mode = all)
+ * Used for debugging.
*/
function dump_mail()
{
@@ -497,8 +503,64 @@ class CMailFile
}
}
+
+ /**
+ * Correct an uncomplete html string
+ *
+ * @param $msg
+ * @return
+ */
+ function checkIfHTML($msg)
+ {
+ if (!preg_match('/^[\s\t]*