예제 #1
0
function emailCollaborators($new_ids, $node)
{
    $query = db_select('users', 'u')->condition('uid', $new_ids)->fields('u', array('name', 'mail'));
    $result = $query->execute();
    foreach ($result as $row) {
        $options = array('absolute' => TRUE);
        $jobPath = url('node/' . $node->nid, $options);
        $jobTitle = $node->title;
        global $user;
        $inviter = $user->name;
        $module = 'tap_job_invite';
        $key = 'key';
        $email = $row->mail;
        $language = language_default();
        $params = array();
        $from = NULL;
        $send = FALSE;
        $message = drupal_mail($module, $key, $email, $language, $params, $from, $send);
        $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
        $message['subject'] = "Collaborator invitation at Tap";
        $message['body'] = array();
        $message['body'][] = "You have invited as a Collaborator by {$inviter} to the job <a href=\"{$jobPath}\">{$jobTitle}</a>. ";
        $message['body'][] = "Log in to join the workroom.";
        // Retrieve the responsible implementation for this message.
        $system = drupal_mail_system($module, $key);
        // Format the message body.
        $message = $system->format($message);
        // Send e-mail.
        $message['result'] = $system->mail($message);
    }
}
예제 #2
0
 /**
  * Assert that the pluggable mail system is functional.
  */
 public function testPluggableFramework()
 {
     // Switch mail backends.
     \Drupal::config('system.mail')->set('interface.default', 'test_php_mail_failure')->save();
     // Get the default MailInterface class instance.
     $mail_backend = drupal_mail_system('default', 'default');
     // Assert whether the default mail backend is an instance of the expected
     // class.
     $this->assertTrue($mail_backend instanceof \Drupal\system_mail_failure_test\Plugin\Mail\TestPhpMailFailure, 'Pluggable mail system is extendable.');
 }
 /**
  * Test to see if the wrapper function is executed correctly.
  */
 function testMailSend()
 {
     // Create an email.
     $subject = $this->randomString(64);
     $body = $this->randomString(128);
     $message = array('id' => 'drupal_mail_test', 'headers' => array('Content-type' => 'text/html'), 'subject' => $subject, 'to' => '*****@*****.**', 'body' => $body);
     // Before we send the email, drupalGetMails should return an empty array.
     $captured_emails = $this->drupalGetMails();
     $this->assertEqual(count($captured_emails), 0, 'The captured emails queue is empty.', 'Email');
     // Send the email.
     drupal_mail_system('simpletest', 'drupal_mail_test')->mail($message);
     // Ensure that there is one email in the captured emails array.
     $captured_emails = $this->drupalGetMails();
     $this->assertEqual(count($captured_emails), 1, 'One email was captured.', 'Email');
     // Assert that the email was sent by iterating over the message properties
     // and ensuring that they are captured intact.
     foreach ($message as $field => $value) {
         $this->assertMail($field, $value, format_string('The email was sent and the value for property @field is intact.', array('@field' => $field)), 'Email');
     }
     // Send additional emails so more than one email is captured.
     for ($index = 0; $index < 5; $index++) {
         $message = array('id' => 'drupal_mail_test_' . $index, 'headers' => array('Content-type' => 'text/html'), 'subject' => $this->randomString(64), 'to' => $this->randomMachineName(32) . '@example.com', 'body' => $this->randomString(512));
         drupal_mail_system('drupal_mail_test', $index)->mail($message);
     }
     // There should now be 6 emails captured.
     $captured_emails = $this->drupalGetMails();
     $this->assertEqual(count($captured_emails), 6, 'All emails were captured.', 'Email');
     // Test different ways of getting filtered emails via drupalGetMails().
     $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test'));
     $this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id.', 'Email');
     $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject));
     $this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id and subject.', 'Email');
     $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject, 'from' => '*****@*****.**'));
     $this->assertEqual(count($captured_emails), 0, 'No emails are returned when querying with an unused from address.', 'Email');
     // Send the last email again, so we can confirm that the
     // drupalGetMails-filter correctly returns all emails with a given
     // property/value.
     drupal_mail_system('drupal_mail_test', $index)->mail($message);
     $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4'));
     $this->assertEqual(count($captured_emails), 2, 'All emails with the same id are returned when filtering by id.', 'Email');
 }