From 77c47a38fad161e398cf7878f6cc5459fc29248f Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 29 Jan 2018 09:56:44 +1300 Subject: [PATCH] FIX Fix support address list in email address fields (#707) --- code/Control/UserDefinedFormController.php | 10 +++++----- tests/Control/UserDefinedFormControllerTest.php | 7 +++++++ tests/UserFormsTest.yml | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 34dcf90..29d2100 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -323,12 +323,12 @@ JS $email->addData($key, $value); } - $email->setFrom($recipient->EmailFrom); - $email->setTo($recipient->EmailAddress); + $email->setFrom(explode(',', $recipient->EmailFrom)); + $email->setTo(explode(',', $recipient->EmailAddress)); $email->setSubject($recipient->EmailSubject); if ($recipient->EmailReplyTo) { - $email->setReplyTo($recipient->EmailReplyTo); + $email->setReplyTo(explode(',', $recipient->EmailReplyTo)); } // check to see if they are a dynamic reply to. eg based on a email field a user selected @@ -336,7 +336,7 @@ JS $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name); if ($submittedFormField && is_string($submittedFormField->Value)) { - $email->setReplyTo($submittedFormField->Value); + $email->setReplyTo(explode(',', $submittedFormField->Value)); } } // check to see if they are a dynamic reciever eg based on a dropdown field a user selected @@ -344,7 +344,7 @@ JS $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name); if ($submittedFormField && is_string($submittedFormField->Value)) { - $email->setTo($submittedFormField->Value); + $email->setTo(explode(',', $submittedFormField->Value)); } } diff --git a/tests/Control/UserDefinedFormControllerTest.php b/tests/Control/UserDefinedFormControllerTest.php index 59280b5..6e2fc5a 100644 --- a/tests/Control/UserDefinedFormControllerTest.php +++ b/tests/Control/UserDefinedFormControllerTest.php @@ -89,6 +89,13 @@ class UserDefinedFormControllerTest extends FunctionalTest // check to see if the user was redirected (301) $this->assertEquals($response->getStatusCode(), 302); $this->assertStringEndsWith('finished#uff', $response->getHeader('Location')); + + // check that multiple email addresses are supported in to and from + $this->assertEmailSent( + 'test1@example.com; test2@example.com', + 'test3@example.com; test4@example.com', + 'Test Email' + ); } public function testValidation() diff --git a/tests/UserFormsTest.yml b/tests/UserFormsTest.yml index 5d1cb1b..f5b2542 100644 --- a/tests/UserFormsTest.yml +++ b/tests/UserFormsTest.yml @@ -264,6 +264,11 @@ SilverStripe\UserForms\Model\Recipient\EmailRecipient: EmailSubject: Email Subject EmailFrom: no-reply@example.com + multiple-email-list: + EmailAddress: test1@example.com, test2@example.com + EmailSubject: Test Email + EmailFrom: test3@example.com, test4@example.com + SilverStripe\UserForms\Model\UserDefinedForm: basic-form-page: Content: '

Here is my form

$UserDefinedForm

Thank you for filling it out

' @@ -275,6 +280,7 @@ SilverStripe\UserForms\Model\UserDefinedForm: - =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.recipient-1 - =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.no-html - =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.no-data + - =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.multiple-email-list page-with-group: Content: 'Page with group'