Skip to content

Commit

Permalink
Better error/setup messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jun 26, 2015
1 parent 460c926 commit 936c46d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
30 changes: 24 additions & 6 deletions htdocs/admin/mails.php
Expand Up @@ -230,7 +230,6 @@
if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
if (preg_match('/^mac/i',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;
Expand Down Expand Up @@ -275,8 +274,21 @@ function initfields()
';
if ($linuxlike)
{
print ' jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);';
print ' jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);';
print '
jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
jQuery("#MAIN_MAIL_SMTP_PORT").hide();
jQuery("#smtp_server_mess").show();
jQuery("#smtp_port_mess").show();
';
}
else
{
print '
jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
jQuery("#smtp_server_mess").hide();
jQuery("#smtp_port_mess").hide();
';
}
print '
}
Expand All @@ -287,7 +299,11 @@ function initfields()
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
}
jQuery("#MAIN_MAIL_SMTP_SERVER").show();
jQuery("#MAIN_MAIL_SMTP_PORT").show();
jQuery("#smtp_server_mess").hide();
jQuery("#smtp_port_mess").hide();
}
}
initfields();
jQuery("#MAIN_MAIL_SENDMODE").change(function() {
Expand Down Expand Up @@ -336,7 +352,7 @@ function initfields()
}
print '</td></tr>';

// Server
// Host server
$var=!$var;
print '<tr '.$bc[$var].'><td>';
if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
Expand All @@ -357,6 +373,7 @@ function initfields()
{
print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $mainserver . '">';
print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="' . $mainserver . '">';
print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
}
else
{
Expand Down Expand Up @@ -389,6 +406,7 @@ function initfields()
{
print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $mainport . '">';
print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="' . $mainport . '">';
print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
}
else
{
Expand Down Expand Up @@ -509,7 +527,7 @@ function initfields()
print $text;
print '</td></tr>';

// Server
// Host server
$var=!$var;
if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
{
Expand Down
16 changes: 12 additions & 4 deletions htdocs/core/class/CMailFile.class.php
Expand Up @@ -39,7 +39,7 @@ class CMailFile
var $subject; // Topic: Subject of email
var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '<myemail@example.com>' or 'John Doe <myemail@example.com>' or '<myemail+trackingid@example.com>')
// Sender: Who send the email ("Sender" has sent emails on behalf of "From").
// Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, use for Sender an email of the protected domain.
// Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain.
// Return-Path: Email where to send bounds.
var $errors_to; // Errors-To: Email where to send errors.
var $addr_to;
Expand Down Expand Up @@ -408,8 +408,8 @@ function sendfile()
$bounce = ''; // By default
if (! empty($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.
// le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA
// Le forcage de la valeure grace à l'option -f de sendmail 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 .= ($bounce?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
}
Expand All @@ -427,7 +427,15 @@ function sendfile()

if (! $res)
{
$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Check your server logs and your firewalls setup";
$this->error="Failed to send mail with php mail";
$linuxlike=1;
if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
if (! $linuxlike)
{
$this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems
}
$this->error.=".<br>Check your server logs and your firewalls setup";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
}
else
Expand Down

0 comments on commit 936c46d

Please sign in to comment.