From e2b370315d50fa7b3717c098e8721eae5cd57426 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 1 Jan 2014 13:51:19 +0100 Subject: [PATCH] Providing sane values for SMTP on CLI --- .../lib/system/mail/SMTPMailSender.class.php | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php b/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php index 1a1cd515d4..31bf103f86 100644 --- a/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php +++ b/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php @@ -63,8 +63,16 @@ class SMTPMailSender extends MailSender { throw new SystemException($this->formatError("can not connect to '".MAIL_SMTP_HOST.":".MAIL_SMTP_PORT."'")); } + $host = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : ''; + if (empty($host)) { + $host = gethostname(); + if ($host === false) { + $host = 'localhost'; + } + } + // send ehlo - $this->write('EHLO '.$_SERVER['HTTP_HOST']); + $this->write('EHLO '.$host); $this->getSMTPStatus(); if ($this->statusCode == 250) { // do authentication @@ -74,7 +82,7 @@ class SMTPMailSender extends MailSender { } else { // send helo - $this->write('HELO '.$_SERVER['HTTP_HOST']); + $this->write('HELO '.$host); $this->getSMTPStatus(); if ($this->statusCode != 250) { throw new SystemException($this->formatError("can not connect to '".MAIL_SMTP_HOST.":".MAIL_SMTP_PORT."'")); @@ -165,10 +173,18 @@ class SMTPMailSender extends MailSender { throw new SystemException($this->formatError("smtp error")); } + $serverName = (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : ''; + if (empty($serverName)) { + $serverName = gethostname(); + if ($serverName === false) { + $serverName = 'localhost'; + } + } + $header = "Date: ".gmdate('r').Mail::$lineEnding ."To: ".$mail->getToString().Mail::$lineEnding - ."Message-ID: <".md5(uniqid())."@".$_SERVER['SERVER_NAME'].">".Mail::$lineEnding + ."Message-ID: <".md5(uniqid())."@".$serverName.">".Mail::$lineEnding ."Subject: ".Mail::encodeMIMEHeader($mail->getSubject()).Mail::$lineEnding .$mail->getHeader(); -- 2.20.1