Merge pull request #12583 from omarabuhussein/dev/core#288
[civicrm-core.git] / CRM / Friend / BAO / Friend.php
index 75e65ba21652abe4a277dabeba5a83319ba7dfc0..0daf23ae528e0a4c062752dc30797f24ef040fe5 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  *
  */
 
@@ -178,7 +178,6 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
     $mailParams['message'] = CRM_Utils_Array::value('suggested_message', $params);
 
     // Default "from email address" is default domain address.
-    // This is normally overridden by one of the if statements below
     list($_, $mailParams['email_from']) = CRM_Core_BAO_Domain::getNameAndEmail();
     list($username, $mailParams['domain']) = explode('@', $mailParams['email_from']);
 
@@ -218,9 +217,11 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
       $mailParams['module'] = 'event';
     }
     elseif ($params['entity_table'] == 'civicrm_pcp') {
-      $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'],
-        'email', 'contact_id'
-      );
+      if (Civi::settings()->get('allow_mail_from_logged_in_contact')) {
+        $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'],
+          'email', 'contact_id'
+        );
+      }
       $urlPath = 'civicrm/pcp/info';
       $mailParams['module'] = 'contribute';
     }
@@ -298,9 +299,18 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
       $fromName = $email;
     }
 
-    // use contact email, CRM-4963
+    if (Civi::settings()->get('allow_mail_from_logged_in_contact')) {
+      // use contact email, CRM-4963
+      if (empty($values['email_from'])) {
+        $values['email_from'] = $email;
+      }
+    }
+
+    // If we have no "email_from" when we get to here, explicitly set it to the default domain email.
     if (empty($values['email_from'])) {
-      $values['email_from'] = $email;
+      list($domainFromName, $domainEmail) = CRM_Core_BAO_Domain::getNameAndEmail();
+      $values['email_from'] = $domainEmail;
+      $values['domain'] = $domainFromName;
     }
 
     $templateParams = array(