diff --git a/include/class/sendmail.class.php b/include/class/sendmail.class.php index 006298fb4..504e7568a 100644 --- a/include/class/sendmail.class.php +++ b/include/class/sendmail.class.php @@ -42,10 +42,7 @@ class Sendmail extends Sendmail_Core { if ( $this->can_send() == false ) throw new Exception(_('Email non envoyé'),EMAIL_LIMIT); - if (!mail($this->mailto, $this->subject, $this->content,$this->header)) - { - throw new Exception('send failed'); - } + parent::send(); // Increment email amount $repo =new Database(); $date=date('Ymd'); @@ -167,7 +164,7 @@ class Sendmail extends Sendmail_Core array(1,$p_dossier,$p_date)); return; } else { - // update + sp_emaoun_email + // update + amount of sent emails $p_repo->exec_sql("update dossier_sent_email set de_sent_email=de_sent_email+1 where dos_id=$1 and de_date=$2", array($p_dossier,$p_date)); } diff --git a/include/config.inc.example b/include/config.inc.example index bb59e7255..d0deec652 100644 --- a/include/config.inc.example +++ b/include/config.inc.example @@ -97,4 +97,7 @@ define ("DEBUGNOALYSS",0); // change NOALYSS_URL with your URL , // with NGINX it is needed to set the NOALYSS_URL , it is the default URL of // your installation, example with https://demo.noalyss.eu -// define ("NOALYSS_URL","https://demo.noalyss.eu"); \ No newline at end of file +// define ("NOALYSS_URL","https://demo.noalyss.eu"); +// For POSTFIX, when sending email from NOALYSS via sendmail an extra parameter is needed +// for the Return-Path, the FROM will be replaced by the Sendmail_Core->from value +//define("MAIL_EXTRA_PARAM","-f [FROM]") diff --git a/include/constant.php b/include/constant.php index f04ac9de6..00cf4ddc5 100644 --- a/include/constant.php +++ b/include/constant.php @@ -452,7 +452,9 @@ function noalyss_class_autoloader($class) } } - +if ( ! defined("MAIL_EXTRA_PARAM")) { + define("MAIL_EXTRA_PARAM","-f [FROM]"); +} spl_autoload_register('\noalyss_class_autoloader', true); require_once NOALYSS_BASE.'/vendor/autoload.php'; diff --git a/include/lib/config_file.php b/include/lib/config_file.php index dbc7bec13..1411ba687 100644 --- a/include/lib/config_file.php +++ b/include/lib/config_file.php @@ -306,6 +306,13 @@ function display_file_config($p_array, $from_setup = 1, $p_os = 1) // your installation, example with https://demo.noalyss.eu $a // define ("NOALYSS_URL","https://demo.noalyss.eu"); $a EOF; + echo <<from value)$a +//define("MAIL_EXTRA_PARAM","-f [FROM]") $a +EOF; } /*! * \brief create the config file diff --git a/include/lib/sendmail_core.class.php b/include/lib/sendmail_core.class.php index 74c6a0b03..2768119de 100644 --- a/include/lib/sendmail_core.class.php +++ b/include/lib/sendmail_core.class.php @@ -46,11 +46,39 @@ class Sendmail_Core protected $content; protected $header; protected $format; + + protected $supplemental_header; //!< $supplemental_header(string) supplemental header to add + protected $supplemental_param; //!< $supplemental_param (string) 5th parameter for mail() + // for postfix, it should be "-f {$this->from}" for the Return-Path + function __construct() { $this->format='PLAIN'; + $this->supplemental_header=""; + $this->supplemental_param=MAIL_EXTRA_PARAM; } - + public function getSupplemental_param() + { + return $this->supplemental_param; + } + + public function setSupplemental_param($supplemental_param) + { + $this->supplemental_param = $supplemental_param; + return $this; + } + + public function getSupplemental_header() + { + return $this->supplemental_header; + } + + public function setSupplemental_header($supplemental_header) + { + $this->supplemental_header = $supplemental_header; + return $this; + } + public function get_format() { return $this->format; } @@ -137,7 +165,7 @@ class Sendmail_Core */ function add_supplemental_header() { - return ''; + return $this->supplemental_header; } /** *@brief create the message before sending @@ -156,6 +184,7 @@ class Sendmail_Core // main header (multipart mandatory) $this->header = "From: " . $this->from . $eol; + $this->header .= "Reply-To: " . $this->from . $eol; $this->header .= "MIME-Version: 1.0" . $eol; $this->header .= $this->add_supplemental_header(); if ($this->format == 'PLAIN') @@ -232,6 +261,7 @@ eof; if ( empty ($this->afile) ) $this->content.=$eol; $this->content .= "--" . $separator . "--"; + $this->supplemental_param= str_replace("[FROM]", $this->from, $this->supplemental_param); } /** @@ -246,8 +276,9 @@ eof; } catch (Exception $e) { throw $e; } - - if (!mail($this->mailto, $this->subject, $this->content,$this->header)) + $encoded_subject = mb_encode_mimeheader( $this->subject, 'UTF-8', 'B'); + + if (!mail($this->mailto,$encoded_subject, $this->content,$this->header,$this->supplemental_param)) { throw new Exception('send failed'); }