adding system check for address parsing
[civicrm-core.git] / CRM / Utils / Mail.php
index 87e62fb0f0afc6cdecd7cd6cd8c9e44beb75aed4..7f6f718149f56dce6b34a181d90a4981742e349e 100644 (file)
@@ -68,8 +68,20 @@ class CRM_Utils_Mail {
         $params['auth'] = FALSE;
       }
 
-      // set the localhost value, CRM-3153
-      $params['localhost'] = CRM_Utils_Array::value('SERVER_NAME', $_SERVER, 'localhost');
+      /*
+       * Set the localhost value, CRM-3153
+       * Use the host name of the web server, falling back to the base URL
+       * (eg when using the PHP CLI), and then falling back to localhost.
+       */
+      $params['localhost'] = CRM_Utils_Array::value(
+        'SERVER_NAME',
+        $_SERVER,
+        CRM_Utils_Array::value(
+          'host',
+          parse_url(CIVICRM_UF_BASEURL),
+          'localhost'
+        )
+      );
 
       // also set the timeout value, lets set it to 30 seconds
       // CRM-7510