Merge pull request #22255 from MegaphoneJon/membership-14-2021
[civicrm-core.git] / CRM / Mailing / Form / Task / AdhocMailing.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Given the selected contacts, prepare a mailing with a hidden group.
20 */
21 class CRM_Mailing_Form_Task_AdhocMailing extends CRM_Contact_Form_Task {
22
23 public function preProcess() {
24 parent::preProcess();
25 $templateTypes = CRM_Mailing_BAO_Mailing::getTemplateTypes();
26 list ($groupId, $ssId) = $this->createHiddenGroup();
27 $mailing = civicrm_api3('Mailing', 'create', [
28 'name' => "",
29 'campaign_id' => NULL,
30 'replyto_email' => "",
31 'template_type' => $templateTypes[0]['name'],
32 'template_options' => ['nonce' => 1],
33 'subject' => "",
34 'body_html' => "",
35 'body_text' => "",
36 'groups' => [
37 'include' => [$groupId],
38 'exclude' => [],
39 'base' => [],
40 ],
41 'mailings' => [
42 'include' => [],
43 'exclude' => [],
44 ],
45 ]);
46
47 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mailing['id']));
48 }
49
50 }