Isolate code for simplemail
This commit is contained in:
parent
003208bc96
commit
49d8233eb8
@ -222,8 +222,9 @@ class CMailFile
|
|||||||
require_once(DOL_DOCUMENT_ROOT."/includes/simplemail/class.mail.php");
|
require_once(DOL_DOCUMENT_ROOT."/includes/simplemail/class.mail.php");
|
||||||
|
|
||||||
$mail = new simplemail();
|
$mail = new simplemail();
|
||||||
|
$mail->set_mode='php'; // php or socket
|
||||||
|
|
||||||
// Bundaries
|
// Boundaries
|
||||||
$mail->B1B = $this->mime_boundary;
|
$mail->B1B = $this->mime_boundary;
|
||||||
$mail->B2B = $this->related_boundary;
|
$mail->B2B = $this->related_boundary;
|
||||||
$mail->B3B = $this->alternative_boundary;
|
$mail->B3B = $this->alternative_boundary;
|
||||||
@ -392,9 +393,8 @@ class CMailFile
|
|||||||
if (empty($conf->global->MAIN_DISABLE_ALL_MAILS))
|
if (empty($conf->global->MAIN_DISABLE_ALL_MAILS))
|
||||||
{
|
{
|
||||||
// Action according to choosed sending method
|
// Action according to choosed sending method
|
||||||
if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' || $conf->global->MAIN_MAIL_SENDMODE == 'simplemail')
|
if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
|
||||||
{
|
{
|
||||||
|
|
||||||
// Use mail php function (default PHP method)
|
// Use mail php function (default PHP method)
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG);
|
dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG);
|
||||||
@ -416,7 +416,7 @@ class CMailFile
|
|||||||
if (! $dest && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
|
if (! $dest && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
|
||||||
{
|
{
|
||||||
$this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
|
$this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
|
||||||
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_DEBUG);
|
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -435,19 +435,68 @@ class CMailFile
|
|||||||
|
|
||||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
|
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
|
||||||
|
|
||||||
if ($conf->global->MAIN_MAIL_SENDMODE == 'simplemail')
|
|
||||||
{
|
|
||||||
$res = $this->simplemail->sendmail();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res = mail($dest,$this->encodetorfc2822($this->subject),$this->message,$this->headers, $bounce);
|
$res = mail($dest,$this->encodetorfc2822($this->subject),$this->message,$this->headers, $bounce);
|
||||||
}
|
|
||||||
|
|
||||||
if (! $res)
|
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";
|
$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";
|
||||||
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_DEBUG);
|
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERROR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_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 == 'simplemail')
|
||||||
|
{
|
||||||
|
// Use simplemmail function (Simplemail method)
|
||||||
|
// --------------------------------------------
|
||||||
|
dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG);
|
||||||
|
dol_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
|
||||||
|
//dol_syslog("CMailFile::sendfile message=\n".$message);
|
||||||
|
|
||||||
|
// If Windows, sendmail_from must be defined
|
||||||
|
if (isset($_SERVER["WINDIR"]))
|
||||||
|
{
|
||||||
|
if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com';
|
||||||
|
@ini_set('sendmail_from',$this->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);
|
||||||
|
|
||||||
|
if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') $dest=$this->getValidAddress($this->addr_to,2);
|
||||||
|
if (! $dest && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
|
||||||
|
{
|
||||||
|
$this->error="Failed to send mail to SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
|
||||||
|
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERROR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_syslog("CMailFile::sendfile: mail start SMTP=".ini_get('SMTP').", PORT=".ini_get('smtp_port'), LOG_DEBUG);
|
||||||
|
|
||||||
|
$this->message=stripslashes($this->message);
|
||||||
|
|
||||||
|
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
|
||||||
|
|
||||||
|
$res = $this->simplemail->sendmail();
|
||||||
|
|
||||||
|
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";
|
||||||
|
$this->error.="\n".$this->simplemail->error_log;
|
||||||
|
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -482,7 +531,6 @@ class CMailFile
|
|||||||
if (! empty($conf->global->MAIN_MAIL_SMTPS_PW)) $this->smtps->setPW($conf->global->MAIN_MAIL_SMTPS_PW);
|
if (! empty($conf->global->MAIN_MAIL_SMTPS_PW)) $this->smtps->setPW($conf->global->MAIN_MAIL_SMTPS_PW);
|
||||||
//$smtps->_msgReplyTo = 'reply@web.com';
|
//$smtps->_msgReplyTo = 'reply@web.com';
|
||||||
|
|
||||||
|
|
||||||
$dest=$this->smtps->getFrom('org');
|
$dest=$this->smtps->getFrom('org');
|
||||||
if (! $dest)
|
if (! $dest)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user