From 95d6260e87a7f50769d0c3f1f7d76aa8c833500c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 9 Feb 2009 00:04:34 +0000 Subject: [PATCH] Added support for SMTPS protocol --- ChangeLog | 1 + htdocs/admin/mails.php | 187 ++++++++----- htdocs/html.form.class.php | 16 +- htdocs/html.formmail.class.php | 82 +++--- htdocs/includes/smtps/SMTPs.php | 57 +++- htdocs/langs/en_US/admin.lang | 11 +- htdocs/langs/en_US/mails.lang | 1 + htdocs/langs/fr_FR/admin.lang | 11 +- htdocs/langs/fr_FR/mails.lang | 1 + htdocs/lib/CMailFile.class.php | 453 ++++++++++++++++++++------------ 10 files changed, 535 insertions(+), 285 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1274c31564f..08d8ddb9946 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,7 @@ For users: - New: Emailing feature can extract civility from contacts. - New: Can create a third party from a member of fundation module. - New: Can set a limit for stock alert to 0. +- New: Support SMTPS. - Fix: Handle correctly the comment in status changing of supplier orders. - Fix: Author, title and topic are correctly encoded in PDF. - Fix: Now HTML output is always UTF8, this solve bad PDF encoding on old users. diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index 039f7d4b786..2fb645db6a9 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2009 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,10 @@ */ /** - \file htdocs/admin/mails.php - \brief Page de configuration des emails - \version $Id$ -*/ + * \file htdocs/admin/mails.php + * \brief Page de configuration des emails + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); @@ -33,7 +33,7 @@ $langs->load("mails"); if (!$user->admin) accessforbidden(); -$substitutionarrayfortest=array( +$substitutionarrayfortest=array( '__ID__' => 'TESTIdRecord', '__EMAIL__' => 'TESTEMail', '__LASTNAME__' => 'TESTLastname', @@ -47,11 +47,14 @@ $substitutionarrayfortest=array( if (isset($_POST["action"]) && $_POST["action"] == 'update') { + dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", $_POST["MAIN_DISABLE_ALL_MAILS"]); + dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", $_POST["MAIN_MAIL_SENDMODE"]); dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", $_POST["MAIN_MAIL_SMTP_PORT"]); dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", $_POST["MAIN_MAIL_SMTP_SERVER"]); + dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", $_POST["MAIN_MAIL_SMTPS_ID"]); + dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", $_POST["MAIN_MAIL_SMTPS_PW"]); dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", $_POST["MAIN_MAIL_EMAIL_FROM"]); - dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", $_POST["MAIN_DISABLE_ALL_MAILS"]); - + Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); exit; } @@ -65,11 +68,11 @@ if ($_POST['addfile'] || $_POST['addfilehtml']) // Set tmp user directory $conf->users->dir_tmp=DOL_DATA_ROOT."/users/".$user->id; $upload_dir = $conf->users->dir_tmp.'/temp/'; - + if (! empty($_FILES['addedfile']['tmp_name'])) { if (! is_dir($upload_dir)) create_exdir($upload_dir); - + if (is_dir($upload_dir)) { if (dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0) > 0) @@ -100,15 +103,18 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml') && ! $_POST['addfile'] && ! $_POST['addfilehtml'] && ! $_POST['cancel']) { $error=0; - + $email_from=''; if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' '; if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>'; $errors_to = $_POST["errorstomail"]; $sendto = $_POST["sendto"]; + $sendtocc = $_POST["sendtocc"]; + $sendtoccc = $_POST["sendtoccc"]; $subject = $_POST['subject']; $body = $_POST['message']; + $deliveryreceipt= $_POST["deliveryreceipt"]; // Create form object include_once('../html.formmail.class.php'); @@ -118,7 +124,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml') $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - + if (empty($_POST["frommail"])) { $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom")).'
'; @@ -135,18 +141,19 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml') { // Le message est-il en html $msgishtml=0; // Message is not HTML - if ($_POST['action'] == 'sendhtml') $msgishtml=1; // Force message to HTML - + if ($_POST['action'] == 'sendhtml') $msgishtml=1; // Force message to HTML + // Pratique les substitutions sur le sujet et message $subject=make_substitutions($subject,$substitutionarrayfortest); $body=make_substitutions($body,$substitutionarrayfortest); - - require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); + + require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); $mailfile = new CMailFile($subject,$sendto,$email_from,$body, - $filepath,$mimetype,$filename, - '', '', 0, $msgishtml,$errors_to); - + $filepath,$mimetype,$filename, + $sendtocc, $sendtoccc, $deliveryreceipt, $msgishtml,$errors_to); + $result=$mailfile->sendfile(); + if ($result) { $message='
'.$langs->trans("MailSuccessfulySent",$email_from,$sendto).'
'; @@ -171,6 +178,7 @@ if (eregi('^win',PHP_OS)) $linuxlike=0; if (eregi('^mac',PHP_OS)) $linuxlike=0; +if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail'; $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port'); if (! $port) $port=25; $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP'); @@ -204,6 +212,22 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit') print ''; print ''; + // Disable + $var=!$var; + print ''; + + // Method + $var=!$var; + print ''; + + // Server $var=!$var; if ($linuxlike) { @@ -213,7 +237,8 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit') { print ''; } - + + // Port $var=!$var; if ($linuxlike) { @@ -223,15 +248,25 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit') { print ''; } - + + // ID + if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + $var=!$var; + print ''; + } + + // PW + if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + $var=!$var; + print ''; + } + + // From $var=!$var; print ''; - $var=!$var; - print ''; - print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("MAIN_DISABLE_ALL_MAILS").''; + print $html->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1); + print '
'.$langs->trans("MAIN_MAIL_SENDMODE").''; + $listofmethods=array(); + $listofmethods['mail']='PHP mail function'; + if ($conf->global->MAIN_FEATURES_LEVEL > 0) $listofmethods['smtps']='SMTPS library ('.$langs->trans("Experimental").')'; + print $html->select_array('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE); + print '
'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'
'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'
'.$langs->trans("MAIN_MAIL_SMTPS_ID").'
'.$langs->trans("MAIN_MAIL_SMTPS_PW").'
'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'
'.$langs->trans("MAIN_DISABLE_ALL_MAILS").''; - print $html->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1); - print '
'; print '
'; @@ -248,8 +283,21 @@ else print ''; print ''; + // Disable $var=!$var; - if ($linuxlike) + print ''; + + // Method + $var=!$var; + print ''; + + // Server + $var=!$var; + if ($linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') { print ''; } @@ -257,9 +305,10 @@ else { print ''; } - + + // Port $var=!$var; - if ($linuxlike) + if ($linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') { print ''; } @@ -267,16 +316,25 @@ else { print ''; } - -// $var=!$var; -// print ''; + // SMTPS ID + $var=!$var; + if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + print ''; + } + + // SMTPS PW + $var=!$var; + if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + print ''; + } + + // From $var=!$var; print ''; - $var=!$var; - print ''; - print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("MAIN_DISABLE_ALL_MAILS").''.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'
'.$langs->trans("MAIN_MAIL_SENDMODE").''; + if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') print 'PHP mail function'; + elseif ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') print 'SMTPS library'; + else { print $langs->trans("Undefined"); } + print '
'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").''.$langs->trans("SeeLocalSendMailSetup").'
'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).''.$conf->global->MAIN_MAIL_SMTP_SERVER.'
'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").''.$langs->trans("SeeLocalSendMailSetup").'
'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).''.$conf->global->MAIN_MAIL_SMTP_PORT.'
'.$langs->trans("MAIN_MAIL_SMTPS_SERVER",ini_get('SMTPs')?ini_get('SMTPs'):$langs->transnoentities("Undefined")).''.$conf->global->MAIN_MAIL_SMTPS_SERVER.'
'.$langs->trans("MAIN_MAIL_SMTPS_ID").''.$conf->global->MAIN_MAIL_SMTPS_ID.'
'.$langs->trans("MAIN_MAIL_SMTPS_PW").''.$conf->global->MAIN_MAIL_SMTPS_PW.'
'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).''.$conf->global->MAIN_MAIL_EMAIL_FROM.'
'.$langs->trans("MAIN_DISABLE_ALL_MAILS").''.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'
'; @@ -300,23 +358,23 @@ else } print ''.$langs->trans("Modify").''; print ''; - - + + // Affichage formulaire de TEST if ($_GET["action"] == 'testconnect') { print '
'; print_titre($langs->trans("DoTestServerAvailability")); - + // Cree l'objet formulaire mail include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); - $mail = new CMailFile('','','',''); + $mail = new CMailFile('','','',''); $result=$mail->check_server_port($server,$port); if ($result) print '
'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'
'; - else + else { print '
'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port); - if ($mail->error) print ' - '.$mail->error; + if ($mail->error) print ' - '.$langs->convToOutputCharset($mail->error,'ISO-8859-1'); print '
'; } print '
'; @@ -324,28 +382,30 @@ else // Affichage formulaire de TEST simple if ($_GET["action"] == 'test') - { + { print '
'; print_titre($langs->trans("DoTestSend")); - + // Cree l'objet formulaire mail include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php"); - $formmail = new FormMail($db); - $formmail->fromname = $conf->global->MAIN_MAIL_EMAIL_FROM; - $formmail->frommail = $conf->global->MAIN_MAIL_EMAIL_FROM; + $formmail = new FormMail($db); + $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM); + $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM); $formmail->withfromreadonly=0; $formmail->withsubstit=0; $formmail->withfrom=1; $formmail->witherrorsto=1; - $formmail->withto=$user->email?$user->email:1; - $formmail->withtocc=1; - $formmail->withtopic=$langs->trans("Test"); + $formmail->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->email?$user->email:1); + $formmail->withtocc=(isset($_POST['sendtocc'])?$_POST['sendtocc']:1); + $formmail->withtoccc=(isset($_POST['sendtoccc'])?$_POST['sendtoccc']:1); + $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test")); $formmail->withtopicreadonly=0; $formmail->withfile=2; - $formmail->withbody=$langs->trans("Test"); + $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("Test")); $formmail->withbodyreadonly=0; $formmail->withcancel=1; $formmail->withdeliveryreceipt=1; + $formmail->withfckeditor=0; // Tableau des substitutions $formmail->substit=$substitutionarrayfortest; // Tableau des parametres complementaires du post @@ -353,39 +413,40 @@ else $formmail->param["models"]="body"; $formmail->param["mailid"]=$mil->id; $formmail->param["returnurl"]=DOL_URL_ROOT."/admin/mails.php"; - + // Init list of files if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') { $formmail->clear_attached_files(); } - + $formmail->show_form('addfile'); - + print '
'; } // Affichage formulaire de TEST HTML if ($_GET["action"] == 'testhtml') - { + { print '
'; print_titre($langs->trans("DoTestSendHTML")); - + // Cree l'objet formulaire mail include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php"); - $formmail = new FormMail($db); + $formmail = new FormMail($db); $formmail->fromname = $conf->global->MAIN_MAIL_EMAIL_FROM; $formmail->frommail = $conf->global->MAIN_MAIL_EMAIL_FROM; $formmail->withfromreadonly=0; $formmail->withsubstit=0; $formmail->withfrom=1; $formmail->witherrorsto=1; - $formmail->withto=$user->email?$user->email:1; - $formmail->withtocc=1; - $formmail->withtopic=$langs->trans("Test"); + $formmail->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->email?$user->email:1); + $formmail->withtocc=(isset($_POST['sendtocc'])?$_POST['sendtocc']:1); + $formmail->withtoccc=(isset($_POST['sendtoccc'])?$_POST['sendtoccc']:1); + $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test")); $formmail->withtopicreadonly=0; $formmail->withfile=2; - $formmail->withbody=$langs->trans("Test"); + $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("Test")); $formmail->withbodyreadonly=0; $formmail->withcancel=1; $formmail->withdeliveryreceipt=1; @@ -397,15 +458,15 @@ else $formmail->param["models"]="body"; $formmail->param["mailid"]=$mil->id; $formmail->param["returnurl"]=DOL_URL_ROOT."/admin/mails.php"; - + // Init list of files if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') { $formmail->clear_attached_files(); } - + $formmail->show_form('addfilehtml'); - + print '
'; } } diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 067d478fcc2..46ae1199da7 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -63,14 +63,14 @@ class Form /** - \brief Affiche un texte+picto avec tooltip sur texte ou sur picto - \param text Texte à afficher - \param htmltext Contenu html du tooltip, codé en html - \param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2, 4=tooltip sur les 2 et forcé en Ajax - \param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est après - \param img Code img du picto - \return string Code html du tooltip (texte+picto) - */ + * \brief Affiche un texte+picto avec tooltip sur texte ou sur picto + * \param text Texte à afficher + * \param htmltext Contenu html du tooltip, codé en html + * \param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2, 4=tooltip sur les 2 et forcé en Ajax + * \param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est après + * \param img Code img du picto + * \return string Code html du tooltip (texte+picto) + */ function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$i=1,$width='200',$shiftX='10') { global $conf; diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php index 2543d9940d4..369b44f1e1b 100644 --- a/htdocs/html.formmail.class.php +++ b/htdocs/html.formmail.class.php @@ -34,14 +34,14 @@ require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); class FormMail { var $db; - + var $fromname; var $frommail; var $replytoname; var $replytomail; var $toname; var $tomail; - + var $withsubstit; // Show substitution array var $withfrom; var $withto; @@ -49,7 +49,7 @@ class FormMail var $withtopic; var $withfile; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files var $withbody; - + var $withfromreadonly; var $withreplytoreadonly; var $withtoreadonly; @@ -57,13 +57,13 @@ class FormMail var $withtopicreadonly; var $withdeliveryreceipt; var $withcancel; - + var $substit=array(); var $param=array(); - + var $error; - + /** \brief Constructeur \param DB handler d'acc�s base de donn�e @@ -71,7 +71,7 @@ class FormMail function FormMail($DB) { $this->db = $DB; - + $this->withfrom=1; $this->withto=1; $this->withtocc=1; @@ -80,7 +80,7 @@ class FormMail $this->withtopic=1; $this->withfile=0; $this->withbody=1; - + $this->withfromreadonly=1; $this->withreplytoreadonly=1; $this->withtoreadonly=0; @@ -89,7 +89,7 @@ class FormMail $this->withtopicreadonly=0; $this->withbodyreadonly=0; $this->withdeliveryreceiptreadonly=0; - + return 1; } @@ -97,18 +97,18 @@ class FormMail * Clear list of attached files in send mail form (stored in session) */ function clear_attached_files() - { + { global $conf,$user; - + $conf->users->dir_tmp=DOL_DATA_ROOT."/users/".$user->id; $upload_dir = $conf->users->dir_tmp.'/temp'; if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir); - + unset($_SESSION["listofpaths"]); unset($_SESSION["listofnames"]); unset($_SESSION["listofmimes"]); } - + /** * Add a file into the list of attached files (stored in SECTION array) * @@ -150,30 +150,30 @@ class FormMail if (! empty($_SESSION["listofmimes"])) $listofmimes=split(';',$_SESSION["listofmimes"]); return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes); } - + /** * \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des propri�t�s - * \param addfileaction Name of action when posting file attachments + * \param addfileaction Name of action when posting file attachments * \remarks this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files */ function show_form($addfileaction='addfile') { global $conf, $langs, $user; - + $langs->load("other"); $langs->load("mails"); - - // Define list of attached files + + // Define list of attached files $listofpaths=array(); $listofnames=array(); $listofmimes=array(); if (! empty($_SESSION["listofpaths"])) $listofpaths=split(';',$_SESSION["listofpaths"]); if (! empty($_SESSION["listofnames"])) $listofnames=split(';',$_SESSION["listofnames"]); if (! empty($_SESSION["listofmimes"])) $listofmimes=split(';',$_SESSION["listofmimes"]); - - + + $form=new Form($DB); - + print "\n\n"; print "
param["returnurl"]."\">\n"; foreach ($this->param as $key=>$value) @@ -181,7 +181,7 @@ class FormMail print "\n"; } print "\n"; - + // Substitution array if ($this->withsubstit) { @@ -194,7 +194,7 @@ class FormMail print $form->textwithhelp($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help); print "\n"; } - + // From if ($this->withfrom) { @@ -211,7 +211,7 @@ class FormMail $fuser->fetch(); print $fuser->getNomUrl(1); } - else + else { print $this->fromname; } @@ -239,7 +239,7 @@ class FormMail print "\n"; } } - + // Replyto if ($this->withreplyto) { @@ -270,18 +270,20 @@ class FormMail print "\n"; } } - + // To if ($this->withto || is_array($this->withto)) { - print '\n"; } - + // CC if ($this->withtocc || is_array($this->withtocc)) { - print '\n"; } - + // Ask delivery receipt if ($this->withdeliveryreceipt) { @@ -434,7 +440,7 @@ class FormMail print $defaultmessage; print ''; } - + } print "\n"; } @@ -477,7 +483,7 @@ class FormMail print ""; print ""; } - + // Message if ($withbody) { @@ -489,7 +495,7 @@ class FormMail print ""; print ""; } - + // Si fichier joint if ($withfile) { @@ -499,7 +505,7 @@ class FormMail print "trans("Upload")."\"/>"; print ""; } - + print "
'.$langs->trans("MailTo").''; + print '
'; + print $form->textwithhelp($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + print ''; if ($this->withtoreadonly) { print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; } else { - print "withto) && ! is_numeric($this->withto)?$this->withto:"")."\">"; + print "withto)?"30":"60")."\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)?$this->withto:"")."\">"; if (is_array($this->withto)) { print " ".$langs->trans("or")." "; @@ -290,18 +292,20 @@ class FormMail } print "
'.$langs->trans("MailCC").''; + print '
'; + print $form->textwithhelp($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + print ''; if ($this->withtoccreadonly) { print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; } else { - print "withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">"; + print "withtocc)?"30":"60")."\" name=\"sendtocc\" value=\"".((! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">"; if (is_array($this->withtocc)) { print " ".$langs->trans("or")." "; @@ -314,14 +318,16 @@ class FormMail // CCC if ($this->withtoccc || is_array($this->withtoccc)) { - print '
'.$langs->trans("MailCCC").''; + print '
'; + print $form->textwithhelp($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + print ''; if ($this->withtocccreadonly) { print (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; } else { - print "withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"")."\">"; + print "withtoccc)?"30":"60")."\" name=\"sendtoccc\" value=\"".((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"")."\">"; if (is_array($this->withtoccc)) { print " ".$langs->trans("or")." "; @@ -330,7 +336,7 @@ class FormMail } print "
"; } diff --git a/htdocs/includes/smtps/SMTPs.php b/htdocs/includes/smtps/SMTPs.php index 536badc5095..76cd7e8ffac 100644 --- a/htdocs/includes/smtps/SMTPs.php +++ b/htdocs/includes/smtps/SMTPs.php @@ -523,7 +523,48 @@ class SMTPs var $_debug = false; + + // DOL_CHANGE LDR + var $log = ''; + var $_errorsTo = ''; + var $_deliveryReceipt = 0; + + function setDeliveryReceipt( $_val = 0 ) + { + $this->_deliveryReceipt = $_val; + } + + function getDeliveryReceipt() + { + return $this->_deliveryReceipt; + } + + function setErrorsTo ( $_strErrorsTo ) + { + if ( $_strErrorsTo ) + $this->_errorsTo = $this->_strip_email ( $_strErrorsTo ); + } + + function getErrorsTo ( $_part = true ) + { + $_retValue = ''; + + if ( $_part === true ) + $_retValue = $this->_errorsTo; + else + $_retValue = $this->_errorsTo[$_part]; + + return $_retValue; + } + + + // ============================================================= + function setDebug ( $_vDebug = false ) + { + $this->_debug = $_vDebug; + } + // ** Class methods /** @@ -1340,6 +1381,7 @@ class SMTPs return $_retValue; } + /** * Method private array _buildAddrList( void ) * @@ -1820,7 +1862,15 @@ class SMTPs if ( $this->_msgPriority != 3 ) $_header .= $this->getPriority(); - $_header .= 'X-Mailer: SMTPs/PHP Mailer' . "\r\n" + + // DOL_CHANGE LDR + if ( $this->getDeliveryReceipt() ) + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; + if ( $this->getErrorsTo() ) + $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; + + + $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n" . 'Mime-Version: 1.0' . "\r\n"; return $_header; @@ -2311,7 +2361,9 @@ class SMTPs function socket_send_str ( $_strSend, $_returnCode = null, $CRLF = "\r\n" ) { + if ($this->_debug) $this->log.=$_strSend . ": "; fputs($this->socket, $_strSend . $CRLF); + if ($this->_debug) $this->log.=$_returnCode . "
"; if ( $_returnCode ) return $this->server_parse($this->socket, $_returnCode); @@ -2383,6 +2435,9 @@ class SMTPs /** * $Log$ + * Revision 1.2 2009/02/09 00:04:35 eldy + * Added support for SMTPS protocol + * * Revision 1.1 2008/04/16 23:11:45 eldy * New: Add action "Test server connectivity" * diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 74cc51fba9d..16375af2a91 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -177,12 +177,15 @@ MeasuringUnit=Measuring unit Emails=E-mails EMailsSetup=E-mails setup EMailsDesc=This page allows you to overwrite your PHP parameters for e-mails sending. In most cases on Unix/Linux OS, your PHP setup is correct and these parameters are useless. -MAIN_MAIL_SMTP_PORT=SMTP Port (By default in php.ini: %s) -MAIN_MAIL_SMTP_SERVER=SMTP Host (By default in php.ini: %s) -MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=SMTP Port (Not defined into PHP on Unix like systems) -MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike=SMTP Host (Not defined into PHP on Unix like systems) +MAIN_MAIL_SMTP_PORT=SMTP/SMTPS Port (By default in php.ini: %s) +MAIN_MAIL_SMTP_SERVER=SMTP/SMTPS Host (By default in php.ini: %s) +MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=SMTP/SMTPS Port (Not defined into PHP on Unix like systems) +MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike=SMTP/SMTPS Host (Not defined into PHP on Unix like systems) MAIN_MAIL_EMAIL_FROM=Sender e-mail for automatic emails (By default in php.ini: %s) MAIN_DISABLE_ALL_MAILS=Disable all e-mails sendings (for test purposes or demos) +MAIN_MAIL_SENDMODE=Method to use to send EMails +MAIN_MAIL_SMTPS_ID=SMTPS ID if authentication required +MAIN_MAIL_SMTPS_PW=SMTPS Password if authentication required FeatureNotAvailableOnLinux=Feature not available on Unix like systems. Test your sendmail program locally. ModuleSetup=Module setup ModulesSetup=Modules setup diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index e87edf5d1c5..92f1057da18 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -87,6 +87,7 @@ ToAddRecipientsChooseHere=To add recipients, choose in those lists NbOfEMailingsReceived=Mass emailings received IdRecord=ID record DeliveryReceipt=Delivery Receipt +YouCanUseCommaSeparatorForSeveralRecipients=You can use the comma separator to specify several recipients. # Module Notifications Notifications=Notifications diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 74b351773b2..e2dd115fe9e 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -176,12 +176,15 @@ MeasuringUnit=Unité de mesure Emails=Emails EMailsSetup=Configuration EMails EMailsDesc=Cette page permet de remplacer les paramètres PHP en rapport avec l'envoi de mails. Dans la plupart des cas sur des OS comme Unix/Linux, les paramètres PHP sont déjà correcte et cette page est inutile. -MAIN_MAIL_SMTP_PORT=Port du serveur SMTP (Par défaut dans php.ini: %s) -MAIN_MAIL_SMTP_SERVER=Nom host ou ip du serveur SMTP (Par défaut dans php.ini: %s) -MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=Port du serveur SMTP (Non défini dans le PHP sur les systemes de type Unix) -MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike=Nom host ou ip du serveur SMTP (Non défini dans le PHP sur les systemes de type Unix) +MAIN_MAIL_SMTP_PORT=Port du serveur SMTP/SMTPS (Par défaut dans php.ini: %s) +MAIN_MAIL_SMTP_SERVER=Nom host ou ip du serveur SMTP/SMTPS (Par défaut dans php.ini: %s) +MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=Port du serveur SMTP/SMTPS (Non défini dans le PHP sur les systemes de type Unix) +MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike=Nom host ou ip du serveur SMTP/SMTPS (Non défini dans le PHP sur les systemes de type Unix) MAIN_MAIL_EMAIL_FROM=EMail émetteur pour envoi emails automatiques (Par défaut dans php.ini: %s) MAIN_DISABLE_ALL_MAILS=Désactiver globalement tout envoi de mails (pour mode test ou démos) +MAIN_MAIL_SENDMODE=Méthode d'envoi des mails +MAIN_MAIL_SMTPS_ID=SMTPS ID si authentification SMTP requise +MAIN_MAIL_SMTPS_PW=SMTPS Password si authentification SMTP requise FeatureNotAvailableOnLinux=Fonctionnalité non disponible sous systemes Unix. Tester votre sendmail localement. ModuleSetup=Configuration du module ModulesSetup=Configuration des modules diff --git a/htdocs/langs/fr_FR/mails.lang b/htdocs/langs/fr_FR/mails.lang index a914431e64f..557ad620557 100644 --- a/htdocs/langs/fr_FR/mails.lang +++ b/htdocs/langs/fr_FR/mails.lang @@ -87,6 +87,7 @@ ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les liste NbOfEMailingsReceived=Mailings de masse reçus IdRecord=ID enregistrement DeliveryReceipt=Accusé de réception +YouCanUseCommaSeparatorForSeveralRecipients=Vous pouvez utiliser le caractère de séparation virgule pour spécifier plusieurs destinataires. # Module Notifications Notifications=Notifications diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php index 250ebfb4167..fb867c6e736 100644 --- a/htdocs/lib/CMailFile.class.php +++ b/htdocs/lib/CMailFile.class.php @@ -52,45 +52,34 @@ class CMailFile var $atleastonefile=0; var $error=''; + var $smtps; // Contains SMTPs object (if this method is used) + /** - \brief CMailFile - \param subject sujet - \param to email destinataire (RFC 2822: "Nom prenom [, ...]" ou "email[, ...]" ou "[, ...]") - \param from email emetteur (RFC 2822: "Nom prenom [, ...]" ou "email[, ...]" ou "[, ...]") - \param msg message - \param filename_list tableau de fichiers attaches - \param mimetype_list tableau des types des fichiers attaches - \param mimefilename_list tableau des noms des fichiers attaches - \param addr_cc email cc - \param addr_bcc email bcc - \param deliveryreceipt demande accuse reception - \param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection + * \brief CMailFile + * \param subject Topic/Subject of mail + * \param to Recipients emails (RFC 2822: "Nom prenom [, ...]" ou "email[, ...]" ou "[, ...]") + * \param from Sender email (RFC 2822: "Nom prenom [, ...]" ou "email[, ...]" ou "[, ...]") + * \param msg Message + * \param filename_list List of files to attach (full path of filename on file system) + * \param mimetype_list List of MIME type of attached files + * \param mimefilename_list List of attached file name in message + * \param addr_cc Email cc + * \param addr_bcc Email bcc + * \param deliveryreceipt Ask a delivery receipt + * \param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection */ function CMailFile($subject,$to,$from,$msg, - $filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(), - $addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='') + $filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(), + $addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='') { - dolibarr_syslog("CMailFile::CMailfile: from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to"); - dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml"); + global $conf; - // Define if there is at least one file - foreach ($filename_list as $i => $val) - { - if ($filename_list[$i]) - { - $this->atleastonefile=1; - dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i]); - } - } + // If ending method not defined + if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail'; - // On defini mime_boundary - $this->mime_boundary = md5(uniqid("dolibarr")); - - // On definit fin de ligne - $this->eol="\n"; - if (eregi('^win',PHP_OS)) $this->eol="\r\n"; - if (eregi('^mac',PHP_OS)) $this->eol="\r"; + dolibarr_syslog("CMailFile::CMailfile: MAIN_MAIL_SENDMODE=".$conf->global->MAIN_MAIL_SENDMODE." charset=".$conf->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to", LOG_DEBUG); + dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml", LOG_DEBUG); // Detect if message is HTML (use fast method) if ($msgishtml == -1) @@ -103,51 +92,257 @@ class CMailFile $this->msgishtml = $msgishtml; } - $smtp_headers = ""; - $mime_headers = ""; - $text_body = ""; - $text_encoded = ""; - - // En-tete dans $smtp_headers - $this->subject = $subject; - $this->addr_from = $from; - $this->errors_to = $errors_to; - $this->addr_to = $to; - $this->addr_cc = $addr_cc; - $this->addr_bcc = $addr_bcc; - $this->deliveryreceipt = $deliveryreceipt; - $smtp_headers = $this->write_smtpheaders(); - - // En-tete suite dans $mime_headers - if ($this->atleastonefile) + // Define if there is at least one file + foreach ($filename_list as $i => $val) { - $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); + if ($filename_list[$i]) + { + $this->atleastonefile=1; + dolibarr_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG); + } } - // Corps message dans $text_body - $text_body = $this->write_body($msg, $filename_list); - - // Corps message suite (fichiers attaches) dans $text_encoded - if ($this->atleastonefile) + // Action according to choosed sending method + if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') { - $text_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); + // Use mail php function (default PHP method) + // ------------------------------------------ + + // On defini mime_boundary + $this->mime_boundary = md5(uniqid("dolibarr")); + + // On definit fin de ligne + $this->eol="\n"; + if (eregi('^win',PHP_OS)) $this->eol="\r\n"; + if (eregi('^mac',PHP_OS)) $this->eol="\r"; + + $smtp_headers = ""; + $mime_headers = ""; + $text_body = ""; + $text_encoded = ""; + + // En-tete dans $smtp_headers + $this->subject = $subject; + $this->addr_from = $from; + $this->errors_to = $errors_to; + $this->addr_to = $to; + $this->addr_cc = $addr_cc; + $this->addr_bcc = $addr_bcc; + $this->deliveryreceipt = $deliveryreceipt; + $smtp_headers = $this->write_smtpheaders(); + + // En-tete suite dans $mime_headers + if ($this->atleastonefile) + { + $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); + } + + // Corps message dans $text_body + $text_body = $this->write_body($msg, $filename_list); + + // Corps message suite (fichiers attaches) dans $text_encoded + if ($this->atleastonefile) + { + $text_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); + } + + // On defini $this->headers et $this->message + $this->headers = $smtp_headers . $mime_headers; + $this->message = $text_body . $text_encoded; + + // On nettoie le header pour qu'il ne se termine pas par un retour chariot. + // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees + // comme des injections mail par les serveurs de messagerie. + $this->headers = eregi_replace("[\r\n]+$","",$this->headers); + } + else if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + // Use SMTPS library + // ------------------------------------------ + + require_once(DOL_DOCUMENT_ROOT."/includes/smtps/SMTPs.php"); + $smtps = new SMTPs(); + $smtps->setCharSet($conf->character_set_client); + $smtps->setSubject($subject); + $smtps->setTO($to); + $smtps->setFrom($from); + if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); + else $smtps->setBodyContent($msg,'plain'); + + if ($this->atleastonefile) + { + foreach ($filename_list as $i => $val) + { + $content=file_get_contents($filename_list[$i]); + $smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]); + } + } + + $smtps->setCC($sentocc); + $smtps->setBCC($sentoccc); + $smtps->setErrorsTo($errors_to); + $smtps->setDeliveryReceipt($deliveryreceipt); + + $this->smtps=$smtps; + } + else + { + // Send mail method not correctly defined + // -------------------------------------- + + return 'Bad value for MAIN_MAIL_SENDMODE constant'; } - // On defini $this->headers et $this->message - $this->headers = $smtp_headers . $mime_headers; - $this->message = $text_body . $text_encoded; - - // On nettoie le header pour qu'il ne se termine pas par un retour chariot. - // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees - // comme des injections mail par les serveurs de messagerie. - $this->headers = eregi_replace("[\r\n]+$","",$this->headers); } /** - \brief Permet d'encoder un fichier - \param sourcefile - \return <0 si erreur, fichier encode si ok + * \brief Send mail that was prepared by constructor + * \return boolean True if mail sent, false otherwise + */ + function sendfile() + { + global $conf; + + $errorlevel=error_reporting(); + error_reporting($errorlevel ^ E_WARNING); // Desactive warnings + + $res=false; + + if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) + { + // Action according to choosed sending method + if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') + { + + // Use mail php function (default PHP method) + // ------------------------------------------ + dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG); + dolibarr_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG); + //dolibarr_syslog("CMailFile::sendfile message=\n".$message); + + + if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); + + + // Si Windows, addr_from doit obligatoirement etre defini + if (isset($_SERVER["WINDIR"])) + { + if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com'; + @ini_set('sendmail_from',getValidAddress($this->addr_from,2)); + } + + // Forcage parametres + if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_set('SMTP',$conf->global->MAIN_MAIL_SMTP_SERVER); + if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_set('smtp_port',$conf->global->MAIN_MAIL_SMTP_PORT); + + $dest=getValidAddress($this->addr_to,2); + if (! $dest) + { + $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Recipient address '$dest' invalid"; + dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_DEBUG); + } + else + { + dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port'), LOG_DEBUG); + //dolibarr_syslog("to=".getValidAddress($this->addr_to,2).", subject=".$this->subject.", message=".stripslashes($this->message).", header=".$this->headers); + + $bounce = ''; + if ($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F) + { + // le return-path dans les header ne fonctionne pas avec tous les MTA + // Le passage par -f est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie. + // La variable definie pose des pb avec certains sendmail securisee (option -f refusee car dangereuse) + $bounce = $this->addr_from != '' ? "-f {$this->addr_from}" : ""; + } + + $res = mail($dest,$this->subject,stripslashes($this->message),$this->headers, $bounce); + + if (! $res) + { + $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Check your server logs and your firewalls setup"; + dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_DEBUG); + } + else + { + dolibarr_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); + } + } + + if (isset($_SERVER["WINDIR"])) + { + @ini_restore('sendmail_from'); + } + + // Forcage parametres + if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_restore('SMTP'); + if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_restore('smtp_port'); + } + else if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + + // Use SMTPS library + // ------------------------------------------ + $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library + + // Forcage parametres + if (empty($conf->global->MAIN_MAIL_SMTP_SERVER)) $conf->global->MAIN_MAIL_SMTP_SERVER=ini_get('SMTP'); + if (empty($conf->global->MAIN_MAIL_SMTP_PORT)) $conf->global->MAIN_MAIL_SMTP_PORT=ini_get('smtp_port'); + + $this->smtps->setHost($conf->global->MAIN_MAIL_SMTP_SERVER); + $this->smtps->setPort($conf->global->MAIN_MAIL_SMTP_PORT); //587 or 25; + + if (! empty($conf->global->MAIN_MAIL_SMTPS_ID)) $this->smtps->setID($conf->global->MAIN_MAIL_SMTPS_ID); + if (! empty($conf->global->MAIN_MAIL_SMTPS_PW)) $this->smtps->setPW($conf->global->MAIN_MAIL_SMTPS_PW); + //$smtps->_msgReplyTo = 'reply@web.com'; + + $dest=$this->smtps->getFrom('org'); + if (! $dest) + { + $this->error="Failed to send mail to SMTP=".$conf->global->MAIN_MAIL_SMTP_SERVER.", PORT=".$conf->global->MAIN_MAIL_SMTP_PORT."
Recipient address '$dest' invalid"; + dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_DEBUG); + } + else + { + if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); + $result=$this->smtps->sendMsg(); + //print $resultvalue; + } + + if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); + + $result=$this->smtps->getErrors(); + if (empty($this->error) && empty($result)) $res=true; + else $res=false; + + } + else + { + + // Send mail method not correctly defined + // -------------------------------------- + + return 'Bad value for MAIN_MAIL_SENDMODE constant'; + } + + } + else + { + $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + dolibarr_syslog("CMailFile::sendfile: ".$this->error); + } + + error_reporting($errorlevel); // Reactive niveau erreur origine + + return $res; + } + + + + /** + * \brief Permet d'encoder un fichier + * \param sourcefile + * \return <0 si erreur, fichier encode si ok */ function _encode_file($sourcefile) { @@ -162,113 +357,37 @@ class CMailFile else { $this->error="Error: Can't read file '$sourcefile'"; - dolibarr_syslog("CMailFile::encode_file: ".$this->error); + dolibarr_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); return -1; } } - /** - \brief Envoi le mail - \return boolean true si mail envoye, false sinon - */ - function sendfile() - { - global $conf; - - dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject); - dolibarr_syslog("CMailFile::sendfile header=\n".$this->headers); - //dolibarr_syslog("CMailFile::sendfile message=\n".$message); - //$this->dump_mail(); - - $errorlevel=error_reporting(); - error_reporting($errorlevel ^ E_WARNING); // Desactive warnings - - $res=false; - - if (! $conf->global->MAIN_DISABLE_ALL_MAILS) - { - // Si Windows, addr_from doit obligatoirement etre defini - if (isset($_SERVER["WINDIR"])) - { - if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com'; - @ini_set('sendmail_from',getValidAddress($this->addr_from,2)); - } - - // Forcage parametres - if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_set('SMTP',$conf->global->MAIN_MAIL_SMTP_SERVER); - if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_set('smtp_port',$conf->global->MAIN_MAIL_SMTP_PORT); - - $dest=getValidAddress($this->addr_to,2); - if (! $dest) - { - $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Recipient address '$dest' invalid"; - dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error); - } - else - { - dolibarr_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')); - //dolibarr_syslog("to=".getValidAddress($this->addr_to,2).", subject=".$this->subject.", message=".stripslashes($this->message).", header=".$this->headers); - - $bounce = ''; - if ($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F) - { - // le return-path dans les header ne fonctionne pas avec tous les MTA - // Le passage par -f est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie. - // La variable definie pose des pb avec certains sendmail securisee (option -f refusee car dangereuse) - $bounce = $this->addr_from != '' ? "-f {$this->addr_from}" : ""; - } - - $res = mail($dest,$this->subject,stripslashes($this->message),$this->headers, $bounce); - - if (! $res) - { - $this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Check your server logs and your firewalls setup"; - dolibarr_syslog("CMailFile::sendfile: mail end error=".$this->error); - } - else - { - dolibarr_syslog("CMailFile::sendfile: mail end success"); - } - } - - if (isset($_SERVER["WINDIR"])) - { - @ini_restore('sendmail_from'); - } - - // Forcage parametres - if (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)) ini_restore('SMTP'); - if (! empty($conf->global->MAIN_MAIL_SMTP_PORT)) ini_restore('smtp_port'); - } - else - { - $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - dolibarr_syslog("CMailFile::sendfile: ".$this->error); - } - - error_reporting($errorlevel); // Reactive niveau erreur origine - - return $res; - } - /** * \brief Ecrit le mail dans un fichier. Utilisation pour le debuggage. */ function dump_mail() { - global $dolibarr_main_data_root; - + global $conf,$dolibarr_main_data_root; + if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir { - $fp = fopen($dolibarr_main_data_root."/dolibarr_mail","w"); - fputs($fp, $this->headers); - fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log - fputs($fp, $this->message); + $fp = fopen($dolibarr_main_data_root."/dolibarr_mail.log","w"); + + if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') + { + fputs($fp, $this->headers); + fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log + fputs($fp, $this->message); + } + elseif ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') + { + fputs($fp, $this->smtps->log); + } + fclose($fp); if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); - } } @@ -295,9 +414,9 @@ class CMailFile if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,2).$this->eol; //$out .= "X-Priority: 3".$this->eol; - $out .= "X-Mailer: Dolibarr version " . DOL_VERSION .$this->eol; + $out .= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol; $out .= "MIME-Version: 1.0".$this->eol; - + if ($this->msgishtml) { if (! $this->atleastonefile) $out.= "Content-Type: text/html; charset=".$conf->character_set_client.$this->eol; @@ -309,7 +428,7 @@ class CMailFile $out.= "Content-Transfer-Encoding: 8bit".$this->eol; } - dolibarr_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out); + dolibarr_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out, LOG_DEBUG); return $out; } @@ -337,14 +456,14 @@ class CMailFile } } //$out.= $this->eol; - dolibarr_syslog("CMailFile::write_mimeheaders mime_header=\n".$out); + dolibarr_syslog("CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG); return $out; } /** - \brief Permet d'ecrire le corps du message - \param msgtext - \param filename_list + * \brief Permet d'ecrire le corps du message + * \param msgtext + * \param filename_list */ function write_body($msgtext, $filename_list) { @@ -370,7 +489,7 @@ class CMailFile // Check if html header already in message $htmlalreadyinmsg=0; if (eregi('^[ \t]*