Merge pull request #4939 from colemanw/CRM-15789
[civicrm-core.git] / CRM / Utils / Mail.php
index 7875f29eae39100013d9bc96717c06f13ce33b99..d076c10732af2ff69d17e84f04bb9878ab02f2f6 100644 (file)
@@ -52,17 +52,17 @@ class CRM_Utils_Mail {
    *   mime_type: mime type of the attachment
    *   cleanName: the user friendly name of the attachmment
    *
-   * @param array $params (by reference)
-   *
-   * @access public
+   * @param array $params
+   *   (by reference).
    *
-   * @return boolean true if a mail was sent, else false
+   * @return boolean
+   *   true if a mail was sent, else false
    */
   public static function send(&$params) {
-    $returnPath       = CRM_Core_BAO_MailSettings::defaultReturnPath();
+    $returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
     $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
-    $emailDomain      = CRM_Core_BAO_MailSettings::defaultDomain();
-    $from             = CRM_Utils_Array::value('from', $params);
+    $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
+    $from = CRM_Utils_Array::value('from', $params);
     if (!$returnPath) {
       $returnPath = self::pluckEmailFromHeader($from);
     }
@@ -85,13 +85,13 @@ class CRM_Utils_Mail {
       $htmlMessage = FALSE;
     }
 
-    $headers         = array();
+    $headers = array();
     // CRM-10699 support custom email headers
     if (!empty($params['headers'])) {
       $headers = array_merge($headers, $params['headers']);
     }
     $headers['From'] = $params['from'];
-    $headers['To']   =
+    $headers['To'] =
       self::formatRFC822Email(
         CRM_Utils_Array::value('toName', $params),
         CRM_Utils_Array::value('toEmail', $params),
@@ -160,20 +160,20 @@ class CRM_Utils_Mail {
     $headers = &$msg->headers($headers);
 
     $to = array($params['toEmail']);
-    $result = null;
-    $mailer =& CRM_Core_Config::getMailer( );
+    $result = NULL;
+    $mailer =& CRM_Core_Config::getMailer();
 
     // Mail_smtp and Mail_sendmail mailers require Bcc anc Cc emails
     // be included in both $to and $headers['Cc', 'Bcc']
     if (get_class($mailer) != "Mail_mail") {
-        //get emails from headers, since these are
-        //combination of name and email addresses.
-        if (!empty($headers['Cc'])) {
-            $to[] = CRM_Utils_Array::value( 'Cc', $headers );
-        }
-        if (!empty($headers['Bcc'])) {
-            $to[] = CRM_Utils_Array::value( 'Bcc', $headers );
-        }
+      //get emails from headers, since these are
+      //combination of name and email addresses.
+      if (!empty($headers['Cc'])) {
+        $to[] = CRM_Utils_Array::value('Cc', $headers);
+      }
+      if (!empty($headers['Bcc'])) {
+        $to[] = CRM_Utils_Array::value('Bcc', $headers);
+      }
     }
     if (is_object($mailer)) {
       $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
@@ -200,7 +200,8 @@ class CRM_Utils_Mail {
    */
   public static function errorMessage($mailer, $result) {
     $message = '<p>' . ts('An error occurred when CiviCRM attempted to send an email (via %1). If you received this error after submitting on online contribution or event registration - the transaction was completed, but we were unable to send the email receipt.', array(
-      1 => 'SMTP')) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM &raquo; System Settings &raquo; Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
+        1 => 'SMTP'
+      )) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM &raquo; System Settings &raquo; Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
 
     if (is_a($mailer, 'Mail_smtp')) {
       $message .= '<ul>' . '<li>' . ts('Your SMTP Username or Password are incorrect.') . '</li>' . '<li>' . ts('Your SMTP Server (machine) name is incorrect.') . '</li>' . '<li>' . ts('You need to use a Port other than the default port 25 in your environment.') . '</li>' . '<li>' . ts('Your SMTP server is just not responding right now (it is down for some reason).') . '</li>';
@@ -210,7 +211,8 @@ class CRM_Utils_Mail {
     }
 
     $message .= '<li>' . ts('The FROM Email Address configured for this feature may not be a valid sender based on your email service provider rules.') . '</li>' . '</ul>' . '<p>' . ts('Check <a href="%1">this page</a> for more information.', array(
-      1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE))) . '</p>';
+        1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE)
+      )) . '</p>';
 
     return $message;
   }
@@ -254,10 +256,11 @@ class CRM_Utils_Mail {
    *
    * Ugly but working.
    *
-   * @param  string $header  the full name + email address string
+   * @param string $header
+   *   The full name + email address string.
    *
-   * @return string          the plucked email address
-   * @static
+   * @return string
+   *   the plucked email address
    */
   public static function pluckEmailFromHeader($header) {
     preg_match('/<([^<]*)>$/', $header, $matches);
@@ -271,9 +274,8 @@ class CRM_Utils_Mail {
   /**
    * Get the Active outBound email
    *
-   * @return boolean true if valid outBound email configuration found, false otherwise
-   * @access public
-   * @static
+   * @return boolean
+   *   true if valid outBound email configuration found, false otherwise
    */
   public static function validOutBoundMail() {
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
@@ -393,7 +395,7 @@ class CRM_Utils_Mail {
    * @param string $html
    * @param string $format
    *
-   * @return array $attachments
+   * @return array
    */
   public static function appendPDF($fileName, $html, $format = NULL) {
     $pdf_filename = CRM_Core_Config::singleton()->templateCompileDir . CRM_Utils_File::makeFileName($fileName);
@@ -405,9 +407,9 @@ class CRM_Utils_Mail {
     $html = preg_replace('/(<html)(.+?xmlns=["\'].[^\s]+["\'])(.+)?(>)/', '\1\3\4', $html);
 
     file_put_contents($pdf_filename, CRM_Utils_PDF_Utils::html2pdf($html,
-      $fileName,
-      TRUE,
-      $format)
+        $fileName,
+        TRUE,
+        $format)
     );
     return array(
       'fullPath' => $pdf_filename,
@@ -416,4 +418,3 @@ class CRM_Utils_Mail {
     );
   }
 }
-