Added support for SMTPS protocol

This commit is contained in:
Laurent Destailleur
2009-02-09 00:04:34 +00:00
parent b568ca1b54
commit 95d6260e87
10 changed files with 535 additions and 285 deletions

View File

@@ -26,6 +26,7 @@ For users:
- New: Emailing feature can extract civility from contacts. - New: Emailing feature can extract civility from contacts.
- New: Can create a third party from a member of fundation module. - New: Can create a third party from a member of fundation module.
- New: Can set a limit for stock alert to 0. - 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: Handle correctly the comment in status changing of supplier orders.
- Fix: Author, title and topic are correctly encoded in PDF. - 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. - Fix: Now HTML output is always UTF8, this solve bad PDF encoding on old users.

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2007-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -17,10 +17,10 @@
*/ */
/** /**
\file htdocs/admin/mails.php * \file htdocs/admin/mails.php
\brief Page de configuration des emails * \brief Page de configuration des emails
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
@@ -47,10 +47,13 @@ $substitutionarrayfortest=array(
if (isset($_POST["action"]) && $_POST["action"] == 'update') 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_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_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_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"); Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
exit; exit;
@@ -107,8 +110,11 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml')
$errors_to = $_POST["errorstomail"]; $errors_to = $_POST["errorstomail"];
$sendto = $_POST["sendto"]; $sendto = $_POST["sendto"];
$sendtocc = $_POST["sendtocc"];
$sendtoccc = $_POST["sendtoccc"];
$subject = $_POST['subject']; $subject = $_POST['subject'];
$body = $_POST['message']; $body = $_POST['message'];
$deliveryreceipt= $_POST["deliveryreceipt"];
// Create form object // Create form object
include_once('../html.formmail.class.php'); include_once('../html.formmail.class.php');
@@ -141,12 +147,13 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml')
$subject=make_substitutions($subject,$substitutionarrayfortest); $subject=make_substitutions($subject,$substitutionarrayfortest);
$body=make_substitutions($body,$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, $mailfile = new CMailFile($subject,$sendto,$email_from,$body,
$filepath,$mimetype,$filename, $filepath,$mimetype,$filename,
'', '', 0, $msgishtml,$errors_to); $sendtocc, $sendtoccc, $deliveryreceipt, $msgishtml,$errors_to);
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)
{ {
$message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$email_from,$sendto).'</div>'; $message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$email_from,$sendto).'</div>';
@@ -171,6 +178,7 @@ if (eregi('^win',PHP_OS)) $linuxlike=0;
if (eregi('^mac',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'); $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
if (! $port) $port=25; if (! $port) $port=25;
$server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP'); $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 '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
// Disable
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
print $html->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
print '</td></tr>';
// Method
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
$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 '</td></tr>';
// Server
$var=!$var; $var=!$var;
if ($linuxlike) if ($linuxlike)
{ {
@@ -214,6 +238,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $conf->global->MAIN_MAIL_SMTP_SERVER . '"></td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $conf->global->MAIN_MAIL_SMTP_SERVER . '"></td></tr>';
} }
// Port
$var=!$var; $var=!$var;
if ($linuxlike) if ($linuxlike)
{ {
@@ -224,14 +249,24 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $conf->global->MAIN_MAIL_SMTP_PORT . '"></td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $conf->global->MAIN_MAIL_SMTP_PORT . '"></td></tr>';
} }
// ID
if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
{
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td><input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $conf->global->MAIN_MAIL_SMTPS_ID . '"></td></tr>';
}
// PW
if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
{
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td><input class="flat" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $conf->global->MAIN_MAIL_SMTPS_PW . '"></td></tr>';
}
// From
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_EMAIL_FROM" size="32" value="' . $conf->global->MAIN_MAIL_EMAIL_FROM . '"></td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td><td><input class="flat" name="MAIN_MAIL_EMAIL_FROM" size="32" value="' . $conf->global->MAIN_MAIL_EMAIL_FROM . '"></td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
print $html->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
print '</td></tr>';
print '</table>'; print '</table>';
print '<br><center>'; print '<br><center>';
@@ -248,8 +283,21 @@ else
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>'; print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
// Disable
$var=!$var; $var=!$var;
if ($linuxlike) print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
// Method
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
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 '</td></tr>';
// Server
$var=!$var;
if ($linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
{ {
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
} }
@@ -258,8 +306,9 @@ else
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_SERVER.'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_SERVER.'</td></tr>';
} }
// Port
$var=!$var; $var=!$var;
if ($linuxlike) if ($linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
{ {
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
} }
@@ -268,15 +317,24 @@ else
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_PORT.'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_PORT.'</td></tr>';
} }
// $var=!$var; // SMTPS ID
// print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_SERVER",ini_get('SMTPs')?ini_get('SMTPs'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_SERVER.'</td></tr>'; $var=!$var;
if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
{
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
}
// SMTPS PW
$var=!$var;
if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
{
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_PW.'</td></tr>';
}
// From
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_EMAIL_FROM.'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_EMAIL_FROM.'</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
print '</table>'; print '</table>';
@@ -316,7 +374,7 @@ else
else else
{ {
print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port); print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
if ($mail->error) print ' - '.$mail->error; if ($mail->error) print ' - '.$langs->convToOutputCharset($mail->error,'ISO-8859-1');
print '</div>'; print '</div>';
} }
print '<br>'; print '<br>';
@@ -331,21 +389,23 @@ else
// Cree l'objet formulaire mail // Cree l'objet formulaire mail
include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php"); 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->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->frommail = $conf->global->MAIN_MAIL_EMAIL_FROM; $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
$formmail->withfromreadonly=0; $formmail->withfromreadonly=0;
$formmail->withsubstit=0; $formmail->withsubstit=0;
$formmail->withfrom=1; $formmail->withfrom=1;
$formmail->witherrorsto=1; $formmail->witherrorsto=1;
$formmail->withto=$user->email?$user->email:1; $formmail->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->email?$user->email:1);
$formmail->withtocc=1; $formmail->withtocc=(isset($_POST['sendtocc'])?$_POST['sendtocc']:1);
$formmail->withtopic=$langs->trans("Test"); $formmail->withtoccc=(isset($_POST['sendtoccc'])?$_POST['sendtoccc']:1);
$formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
$formmail->withtopicreadonly=0; $formmail->withtopicreadonly=0;
$formmail->withfile=2; $formmail->withfile=2;
$formmail->withbody=$langs->trans("Test"); $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("Test"));
$formmail->withbodyreadonly=0; $formmail->withbodyreadonly=0;
$formmail->withcancel=1; $formmail->withcancel=1;
$formmail->withdeliveryreceipt=1; $formmail->withdeliveryreceipt=1;
$formmail->withfckeditor=0;
// Tableau des substitutions // Tableau des substitutions
$formmail->substit=$substitutionarrayfortest; $formmail->substit=$substitutionarrayfortest;
// Tableau des parametres complementaires du post // Tableau des parametres complementaires du post
@@ -380,12 +440,13 @@ else
$formmail->withsubstit=0; $formmail->withsubstit=0;
$formmail->withfrom=1; $formmail->withfrom=1;
$formmail->witherrorsto=1; $formmail->witherrorsto=1;
$formmail->withto=$user->email?$user->email:1; $formmail->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->email?$user->email:1);
$formmail->withtocc=1; $formmail->withtocc=(isset($_POST['sendtocc'])?$_POST['sendtocc']:1);
$formmail->withtopic=$langs->trans("Test"); $formmail->withtoccc=(isset($_POST['sendtoccc'])?$_POST['sendtoccc']:1);
$formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
$formmail->withtopicreadonly=0; $formmail->withtopicreadonly=0;
$formmail->withfile=2; $formmail->withfile=2;
$formmail->withbody=$langs->trans("Test"); $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("Test"));
$formmail->withbodyreadonly=0; $formmail->withbodyreadonly=0;
$formmail->withcancel=1; $formmail->withcancel=1;
$formmail->withdeliveryreceipt=1; $formmail->withdeliveryreceipt=1;

View File

@@ -63,14 +63,14 @@ class Form
/** /**
\brief Affiche un texte+picto avec tooltip sur texte ou sur picto * \brief Affiche un texte+picto avec tooltip sur texte ou sur picto
\param text Texte <20> afficher * \param text Texte <20> afficher
\param htmltext Contenu html du tooltip, cod<6F> en html * \param htmltext Contenu html du tooltip, cod<6F> en html
\param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2, 4=tooltip sur les 2 et forc<72> en Ajax * \param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2, 4=tooltip sur les 2 et forc<72> en Ajax
\param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apr<70>s * \param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apr<70>s
\param img Code img du picto * \param img Code img du picto
\return string Code html du tooltip (texte+picto) * \return string Code html du tooltip (texte+picto)
*/ */
function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$i=1,$width='200',$shiftX='10') function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$i=1,$width='200',$shiftX='10')
{ {
global $conf; global $conf;

View File

@@ -274,14 +274,16 @@ class FormMail
// To // To
if ($this->withto || is_array($this->withto)) if ($this->withto || is_array($this->withto))
{ {
print '<tr><td width="180">'.$langs->trans("MailTo").'</td><td>'; print '<tr><td width="180">';
print $form->textwithhelp($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
print '</td><td>';
if ($this->withtoreadonly) if ($this->withtoreadonly)
{ {
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
} }
else else
{ {
print "<input size=\"30\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)?$this->withto:"")."\">"; print "<input size=\"".(is_array($this->withto)?"30":"60")."\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)?$this->withto:"")."\">";
if (is_array($this->withto)) if (is_array($this->withto))
{ {
print " ".$langs->trans("or")." "; print " ".$langs->trans("or")." ";
@@ -294,14 +296,16 @@ class FormMail
// CC // CC
if ($this->withtocc || is_array($this->withtocc)) if ($this->withtocc || is_array($this->withtocc))
{ {
print '<tr><td width="180">'.$langs->trans("MailCC").'</td><td>'; print '<tr><td width="180">';
print $form->textwithhelp($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
print '</td><td>';
if ($this->withtoccreadonly) if ($this->withtoccreadonly)
{ {
print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"";
} }
else else
{ {
print "<input size=\"30\" name=\"sendtocc\" value=\"".((! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">"; print "<input size=\"".(is_array($this->withtocc)?"30":"60")."\" name=\"sendtocc\" value=\"".((! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">";
if (is_array($this->withtocc)) if (is_array($this->withtocc))
{ {
print " ".$langs->trans("or")." "; print " ".$langs->trans("or")." ";
@@ -314,14 +318,16 @@ class FormMail
// CCC // CCC
if ($this->withtoccc || is_array($this->withtoccc)) if ($this->withtoccc || is_array($this->withtoccc))
{ {
print '<tr><td width="180">'.$langs->trans("MailCCC").'</td><td>'; print '<tr><td width="180">';
print $form->textwithhelp($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
print '</td><td>';
if ($this->withtocccreadonly) if ($this->withtocccreadonly)
{ {
print (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; print (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"";
} }
else else
{ {
print "<input size=\"30\" name=\"sendtocc\" value=\"".((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"")."\">"; print "<input size=\"".(is_array($this->withtoccc)?"30":"60")."\" name=\"sendtoccc\" value=\"".((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"")."\">";
if (is_array($this->withtoccc)) if (is_array($this->withtoccc))
{ {
print " ".$langs->trans("or")." "; print " ".$langs->trans("or")." ";

View File

@@ -523,7 +523,48 @@ class SMTPs
var $_debug = false; 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 // ** Class methods
/** /**
@@ -1340,6 +1381,7 @@ class SMTPs
return $_retValue; return $_retValue;
} }
/** /**
* Method private array _buildAddrList( void ) * Method private array _buildAddrList( void )
* *
@@ -1820,7 +1862,15 @@ class SMTPs
if ( $this->_msgPriority != 3 ) if ( $this->_msgPriority != 3 )
$_header .= $this->getPriority(); $_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"; . 'Mime-Version: 1.0' . "\r\n";
return $_header; return $_header;
@@ -2311,7 +2361,9 @@ class SMTPs
function socket_send_str ( $_strSend, $_returnCode = null, $CRLF = "\r\n" ) function socket_send_str ( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
{ {
if ($this->_debug) $this->log.=$_strSend . ":&nbsp;";
fputs($this->socket, $_strSend . $CRLF); fputs($this->socket, $_strSend . $CRLF);
if ($this->_debug) $this->log.=$_returnCode . "<br>";
if ( $_returnCode ) if ( $_returnCode )
return $this->server_parse($this->socket, $_returnCode); return $this->server_parse($this->socket, $_returnCode);
@@ -2383,6 +2435,9 @@ class SMTPs
/** /**
* $Log$ * $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 * Revision 1.1 2008/04/16 23:11:45 eldy
* New: Add action "Test server connectivity" * New: Add action "Test server connectivity"
* *

View File

@@ -177,12 +177,15 @@ MeasuringUnit=Measuring unit
Emails=E-mails Emails=E-mails
EMailsSetup=E-mails setup 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. 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: <b>%s</b>) MAIN_MAIL_SMTP_PORT=SMTP/SMTPS Port (By default in php.ini: <b>%s</b>)
MAIN_MAIL_SMTP_SERVER=SMTP Host (By default in php.ini: <b>%s</b>) MAIN_MAIL_SMTP_SERVER=SMTP/SMTPS Host (By default in php.ini: <b>%s</b>)
MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=SMTP Port (Not defined into PHP on Unix like systems) MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=SMTP/SMTPS 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_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: <b>%s</b>) MAIN_MAIL_EMAIL_FROM=Sender e-mail for automatic emails (By default in php.ini: <b>%s</b>)
MAIN_DISABLE_ALL_MAILS=Disable all e-mails sendings (for test purposes or demos) 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. FeatureNotAvailableOnLinux=Feature not available on Unix like systems. Test your sendmail program locally.
ModuleSetup=Module setup ModuleSetup=Module setup
ModulesSetup=Modules setup ModulesSetup=Modules setup

View File

@@ -87,6 +87,7 @@ ToAddRecipientsChooseHere=To add recipients, choose in those lists
NbOfEMailingsReceived=Mass emailings received NbOfEMailingsReceived=Mass emailings received
IdRecord=ID record IdRecord=ID record
DeliveryReceipt=Delivery Receipt DeliveryReceipt=Delivery Receipt
YouCanUseCommaSeparatorForSeveralRecipients=You can use the <b>comma</b> separator to specify several recipients.
# Module Notifications # Module Notifications
Notifications=Notifications Notifications=Notifications

View File

@@ -176,12 +176,15 @@ MeasuringUnit=Unité de mesure
Emails=Emails Emails=Emails
EMailsSetup=Configuration 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. 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: <b>%s</b>) MAIN_MAIL_SMTP_PORT=Port du serveur SMTP/SMTPS (Par défaut dans php.ini: <b>%s</b>)
MAIN_MAIL_SMTP_SERVER=Nom host ou ip du serveur SMTP (Par défaut dans php.ini: <b>%s</b>) MAIN_MAIL_SMTP_SERVER=Nom host ou ip du serveur SMTP/SMTPS (Par défaut dans php.ini: <b>%s</b>)
MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike=Port du serveur SMTP (Non défini dans le PHP sur les systemes de type Unix) 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 (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: <b>%s</b>) MAIN_MAIL_EMAIL_FROM=EMail émetteur pour envoi emails automatiques (Par défaut dans php.ini: <b>%s</b>)
MAIN_DISABLE_ALL_MAILS=Désactiver globalement tout envoi de mails (pour mode test ou démos) 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. FeatureNotAvailableOnLinux=Fonctionnalité non disponible sous systemes Unix. Tester votre sendmail localement.
ModuleSetup=Configuration du module ModuleSetup=Configuration du module
ModulesSetup=Configuration des modules ModulesSetup=Configuration des modules

View File

@@ -87,6 +87,7 @@ ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les liste
NbOfEMailingsReceived=Mailings de masse reçus NbOfEMailingsReceived=Mailings de masse reçus
IdRecord=ID enregistrement IdRecord=ID enregistrement
DeliveryReceipt=Accusé de réception DeliveryReceipt=Accusé de réception
YouCanUseCommaSeparatorForSeveralRecipients=Vous pouvez utiliser le caractère de séparation <b>virgule</b> pour spécifier plusieurs destinataires.
# Module Notifications # Module Notifications
Notifications=Notifications Notifications=Notifications

View File

@@ -52,45 +52,34 @@ class CMailFile
var $atleastonefile=0; var $atleastonefile=0;
var $error=''; var $error='';
var $smtps; // Contains SMTPs object (if this method is used)
/** /**
\brief CMailFile * \brief CMailFile
\param subject sujet * \param subject Topic/Subject of mail
\param to email destinataire (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]") * \param to Recipients emails (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param from email emetteur (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]") * \param from Sender email (RFC 2822: "Nom prenom <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]")
\param msg message * \param msg Message
\param filename_list tableau de fichiers attaches * \param filename_list List of files to attach (full path of filename on file system)
\param mimetype_list tableau des types des fichiers attaches * \param mimetype_list List of MIME type of attached files
\param mimefilename_list tableau des noms des fichiers attaches * \param mimefilename_list List of attached file name in message
\param addr_cc email cc * \param addr_cc Email cc
\param addr_bcc email bcc * \param addr_bcc Email bcc
\param deliveryreceipt demande accuse reception * \param deliveryreceipt Ask a delivery receipt
\param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection * \param msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
*/ */
function CMailFile($subject,$to,$from,$msg, function CMailFile($subject,$to,$from,$msg,
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(), $filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='') $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"); global $conf;
dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml");
// Define if there is at least one file // If ending method not defined
foreach ($filename_list as $i => $val) if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
{
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]);
}
}
// On defini mime_boundary 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);
$this->mime_boundary = md5(uniqid("dolibarr")); dolibarr_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml", LOG_DEBUG);
// 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";
// Detect if message is HTML (use fast method) // Detect if message is HTML (use fast method)
if ($msgishtml == -1) if ($msgishtml == -1)
@@ -103,51 +92,257 @@ class CMailFile
$this->msgishtml = $msgishtml; $this->msgishtml = $msgishtml;
} }
$smtp_headers = ""; // Define if there is at least one file
$mime_headers = ""; foreach ($filename_list as $i => $val)
$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); 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 // Action according to choosed sending method
$text_body = $this->write_body($msg, $filename_list); if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
// Corps message suite (fichiers attaches) dans $text_encoded
if ($this->atleastonefile)
{ {
$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 * \brief Send mail that was prepared by constructor
\param sourcefile * \return boolean True if mail sent, false otherwise
\return <0 si erreur, fichier encode si ok */
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')."<br>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')."<br>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."<br>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) function _encode_file($sourcefile)
{ {
@@ -162,113 +357,37 @@ class CMailFile
else else
{ {
$this->error="Error: Can't read file '$sourcefile'"; $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; 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')."<br>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')."<br>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. * \brief Ecrit le mail dans un fichier. Utilisation pour le debuggage.
*/ */
function dump_mail() 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 if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir
{ {
$fp = fopen($dolibarr_main_data_root."/dolibarr_mail","w"); $fp = fopen($dolibarr_main_data_root."/dolibarr_mail.log","w");
fputs($fp, $this->headers);
fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
fputs($fp, $this->message); {
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); fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@chmod($outputfile, octdec($conf->global->MAIN_UMASK)); @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
} }
} }
@@ -295,7 +414,7 @@ class CMailFile
if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".getValidAddress($this->addr_from,2).$this->eol; 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-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; $out .= "MIME-Version: 1.0".$this->eol;
if ($this->msgishtml) if ($this->msgishtml)
@@ -309,7 +428,7 @@ class CMailFile
$out.= "Content-Transfer-Encoding: 8bit".$this->eol; $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; return $out;
} }
@@ -337,14 +456,14 @@ class CMailFile
} }
} }
//$out.= $this->eol; //$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; return $out;
} }
/** /**
\brief Permet d'ecrire le corps du message * \brief Permet d'ecrire le corps du message
\param msgtext * \param msgtext
\param filename_list * \param filename_list
*/ */
function write_body($msgtext, $filename_list) function write_body($msgtext, $filename_list)
{ {