Based on this issue I was able to create an onEmailSend() function and modify the routing of form email based on form select values. So far, so good (great, actually!).
But when I applied my approach to forms with attachments, one of two problems occur. Here is a sample, where example-form has no attachments and works fine, but example-form-2 shows the two issues:
public function onEmailSend(Event $e)
{
switch ($e['vars']['form']->name()) {
case 'example-form':
if ($e['vars']['form']->value('category') == 'Customer Service') {
$e['params'] = array('to' => array('cs@example.com'));
}
elseif ($e['vars']['form']->value('category') == 'Careers') {
$e['params'] = array('to' => array('hr@example.com', 'another@example.com'));
}
else {
$e['params'] = array('to' => array('info@example.com'));
}
break;
case 'example-form-2':
// CASE A: The following will send but without attachments
$e['params'] = array('to' => array('thekenshow@sent.as', 'thekenshow@live.ca'));
// CASE B: The following never completes to confirmation message and nothing is sent
$e['params'] += array('cc' => 'thekenshow@live.ca');
break;
}
}
I've also seen the CASE B fail-to-send problem with the $e['params'] = array('to'... version.
For CASE A above, the email arrives with a description of the attachment but nothing attached:
Attach up to 3 files (DOC/DOCX, XLS/XLSX, PDF. Maximum 5 Mb each):
* Test.doc
* application/msword
* 222720
* user/data/example-form/attachments/Test.doc
The form.en.md process section looks like this:
process:
-
save:
fileprefix: rfp-
dateformat: Ymd-His-u
extension: txt
body: '{% include ''forms/data.txt.twig'' %}'
-
email:
-
subject: '[Example] from {{ form.value.contactname|e }}'
body: '{% include ''forms/data.html.twig'' %}'
to: hr@example.com
to_name: 'Example Form List'
reply_to: '{{ form.value.contactemail|e }}'
attachments:
- exampleattach
The attachment field configuration looks like this:
Based on this issue I was able to create an onEmailSend() function and modify the routing of form email based on form select values. So far, so good (great, actually!).
But when I applied my approach to forms with attachments, one of two problems occur. Here is a sample, where
example-form
has no attachments and works fine, butexample-form-2
shows the two issues:I've also seen the CASE B fail-to-send problem with the
$e['params'] = array('to'...
version.For CASE A above, the email arrives with a description of the attachment but nothing attached:
The form.en.md process section looks like this:
The attachment field configuration looks like this:
Whether or not avoid_overwriting is true seems to make no difference.