Merge pull request #4657 from monishdeb/CRM-14512
[civicrm-core.git] / CRM / Mailing / Form / Test.php
index c3028898add843a6862412f16832c65137e33475..620d6b9c54b333012a5c0f8d93c0a644512e9474 100644 (file)
@@ -39,7 +39,7 @@
 class CRM_Mailing_Form_Test extends CRM_Core_Form {
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
    *
    * @return void
    * @access public
@@ -57,7 +57,7 @@ class CRM_Mailing_Form_Test extends CRM_Core_Form {
   }
 
   /**
-   * This function sets the default values for the form.
+   * Set default values for the form.
    *
    * @access public
    *
@@ -172,9 +172,9 @@ class CRM_Mailing_Form_Test extends CRM_Core_Form {
   /**
    * Form rule to send out a test mailing.
    *
-   * @param array $params     Array of the form values
-   * @param array $files      Any files posted to the form
-   * @param array $self       an current this object
+   * @param aray $testParams
+   * @param array $files Any files posted to the form
+   * @param array $self an current this object
    *
    * @return boolean          true on successful SMTP handoff
    * @access public
@@ -215,7 +215,7 @@ class CRM_Mailing_Form_Test extends CRM_Core_Form {
           $testParams['emails'][] = $email;
           $emails .= $emails ? ",'$email'" : "'$email'";
           if (!CRM_Utils_Rule::email($email)) {
-            CRM_Core_Session::setStatus(ts('Please enter a valid email addresses.'), ts('Test not sent.'), 'error');
+            CRM_Core_Session::setStatus(ts('Please enter a valid email address.'), ts('Test not sent.'), 'error');
             $error = TRUE;
           }
         }
@@ -288,6 +288,7 @@ WHERE      e.email IN ($emails)
 AND        e.on_hold = 0
 AND        c.is_opt_out = 0
 AND        c.do_not_email = 0
+AND        c.is_deleted = 0
 AND        c.is_deceased = 0
 GROUP BY   e.id
 ORDER BY   e.is_bulkmail DESC, e.is_primary DESC
@@ -305,7 +306,9 @@ ORDER BY   e.is_bulkmail DESC, e.is_primary DESC
 
       $dao->free();
       foreach ($testParams['emails'] as $key => $email) {
-        $email = trim($email);
+        // Email addresses are forced to lower case when saved, so ensure
+        // we have the same case when comparing.
+        $email = trim(strtolower($email));
         $contactId = $emailId = NULL;
         if (array_key_exists($email, $emailDetail)) {
           $emailId = $emailDetail[$email]['email_id'];