*/
public $_templates;
+ /**
+ * Email addresses to send to.
+ *
+ * @var array
+ */
+ protected $emails = [];
+
/**
* Store "to" contact details.
* @var array
if ($to->getValue()) {
foreach ($this->getEmails($to) as $value) {
$contactId = $value['contact_id'];
- $email = $value['email'];
if ($contactId) {
$this->_contactIds[] = $this->_toContactIds[] = $contactId;
- $this->_toContactEmails[] = $email;
$this->_allContactIds[] = $contactId;
}
}
*/
public function postProcess() {
$this->bounceIfSimpleMailLimitExceeded(count($this->_contactIds));
-
- // check and ensure that
$formValues = $this->controller->exportValues($this->getName());
$this->submit($formValues);
}
if (!isset($this->_contactDetails[$contactId])) {
continue;
}
- $email = $this->_toContactEmails[$key];
+ $email = $this->getEmail($key);
// prevent duplicate emails if same email address is selected CRM-4067
// we should allow same emails for different contacts
$details = $this->_contactDetails[$contactId];
return $fromEmailValues;
}
+ /**
+ * Get the relevant emails.
+ *
+ * @param int $index
+ *
+ * @return string
+ */
+ protected function getEmail(int $index): string {
+ if (empty($this->emails)) {
+ $toEmails = explode(',', $this->getSubmittedValue('to'));
+ foreach ($toEmails as $value) {
+ $parts = explode('::', $value);
+ $this->emails[] = $parts[1];
+ }
+ }
+ return $this->emails[$index];
+ }
+
}
Civi::settings()->set('allow_mail_from_logged_in_contact', 1);
$loggedInContactID = $this->createLoggedInUser();
- /* @var CRM_Contact_Form_Task_Email $form*/
- $form = $this->getFormObject('CRM_Contact_Form_Task_Email');
-
- for ($i = 0; $i < 27; $i++) {
- $email = 'spy' . $i . '@secretsquirrels.com';
- $contactID = $this->individualCreate(['email' => $email]);
- $form->_contactIds[$contactID] = $contactID;
- $form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => $email])] = $email;
- }
- $deceasedContactID = $this->individualCreate(['is_deceased' => 1, 'email' => 'dead@example.com']);
- $form->_contactIds[$deceasedContactID] = $deceasedContactID;
- $form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => 'dead@example.com'])] = 'dead@example.com';
-
$loggedInEmail = $this->callAPISuccess('Email', 'create', [
'email' => 'mickey@mouse.com',
'location_type_id' => 1,
'signature_text' => 'This is a test Signature',
'signature_html' => '<p>This is a test Signature</p>',
]);
+
+ $to = $form_contactIds = $form_toContactEmails = [];
+ for ($i = 0; $i < 27; $i++) {
+ $email = 'spy' . $i . '@secretsquirrels.com';
+ $contactID = $this->individualCreate(['email' => $email]);
+ $form_contactIds[$contactID] = $contactID;
+ $to[] = $contactID . '::' . $email;
+ }
+ $deceasedContactID = $this->individualCreate(['is_deceased' => 1, 'email' => 'dead@example.com']);
+ $to[] = $deceasedContactID . '::' . 'email@example.com';
+ /* @var CRM_Contact_Form_Task_Email $form*/
+ $form = $this->getFormObject('CRM_Contact_Form_Task_Email', [
+ 'to' => implode(',', $to),
+ ]);
+ $form->_contactIds = $form_contactIds;
+ $form->_contactIds[$deceasedContactID] = $deceasedContactID;
+
$form->_allContactIds = $form->_toContactIds = $form->_contactIds;
- $form->_emails = [$loggedInEmail['id'] => 'mickey@mouse.com'];
$form->_fromEmails = [$loggedInEmail['id'] => 'mickey@mouse.com'];
// This rule somehow disappears if there's a form-related test before us,
// so register it again. See packages/HTML/QuickForm/file.php.
+ // update - actually - it's never registered. Even in form made
+ // I can see it missing - It's really weird.
$form->registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');
$form->isSearchContext = FALSE;
$form->buildForm();
$form->submit(array_merge($form->_defaultValues, [
+ // @todo - it's better to pass these into getForm
+ // and access them on the form using $this->getSubmittedValue().
'from_email_address' => $loggedInEmail['id'],
'subject' => 'Really interesting stuff',
'bcc_id' => $bcc,
]);
$contribution1 = $this->contributionCreate(['contact_id' => $contact2]);
$contribution2 = $this->contributionCreate(['total_amount' => 999, 'contact_id' => $contact1]);
- $form = $this->getFormObject('CRM_Contribute_Form_Task_Email', ['cc_id' => '', 'bcc_id' => ''], [], [
+ $form = $this->getFormObject('CRM_Contribute_Form_Task_Email', [
+ 'cc_id' => '',
+ 'bcc_id' => '',
+ 'to' => implode(',', [
+ $contact1 . '::teresajensen-nielsen65@spamalot.co.in',
+ $contact2 . '::bob@example.com',
+ ]),
+ 'subject' => '{contact.display_name}',
+ 'text_message' => '{contribution.total_amount}',
+ 'html_message' => '{domain.name}',
+ ], [], [
'radio_ts' => 'ts_sel',
- 'task' => CRM_Contribute_Task::TASK_EMAIL,
+ 'task' => CRM_Core_Task::TASK_EMAIL,
'mark_x_' . $contribution1 => 1,
'mark_x_' . $contribution2 => 1,
]);
$form->set('cid', $contact1 . ',' . $contact2);
$form->buildForm();
$this->assertEquals('<br/><br/>--Benny, Benny', $form->_defaultValues['html_message']);
+ $form->postProcess();
}
}