Drupal 7.60, Civicrm 5.6.0

I want to give to my users the ability to send a mail or mailing to a selection of recipients, based upon some cross selection of fields values.

Views is a good tool for this cross selection and to get a recipients list.

But then, how can I pass this list to the Mailing Form ?

  • I'm assuming the field values for the cross selection are Drupal fields, not CiviCRM fields? Nov 7 '18 at 16:03

I'm assuming what you have is a bunch of Drupal users that you are segmenting using Drupal field values.

Step 1 Go here civicrm/admin/synchUser?reset=1 and make sure all your Drupal users are in CiviCRM.

Step 2. Create a custom field for an individual. Make it Yes/No. Call it My Group or whatever. Make it searchable.

Step 3. Make sure that you have the custom field group added to the database config in settings.php /civicrm/admin/setting/uf?reset=1 so you can use it in Drupal Views.

Step 4. Create a view of CiviCRM contacts. Use a Drupal UID relationship so you can filter them into the group you want. Add the custom field you created in Step 2 to the view. Add a VBO filed. Modify the Entity value of the custom field. Bulk edit the custom field and set it to 1.

Step 5. Go to CiviCRM and search for contacts with the custom field set to yes. Add them to a new Mailing Group.

So you could have this as a smart group. You users just have to use VBO to add in the custom field value to update the smart group.

  • Thank you Tony : seems clever and smart ! Just one missing step : how would you automatically unflag the custom field afterwards (in order to use the same smart Group for other mailings) ? Nov 8 '18 at 15:59
  • Maybe dont do that....What you could do is have a custom field for each mailing group in CiviCRM - so checking/unchecking them in VBO dynamically changes membership of each smart group.... Nov 9 '18 at 9:31
  • I have to think about it Nov 10 '18 at 10:26
  • I have an other concern : when I create a new custom field (Yes/No, searchable), it does not appear in the VBO config Token List, while all other existing custom fields are listed. Any idea to fix that ? Nov 10 '18 at 10:35
  • Check it's in a custom field group that you added into your settings.php file - CiviCRM CMS integration etc etc. Also, does it have to be added in as a field in the view before you can access it? Nov 11 '18 at 12:39

You can create mailing jobs and execute them programmatically.


  1. Create a mailing
  2. Create mailing job through code:
  3. $new_job = new CRM_Mailing_BAO_MailingJob(); $params = array( 'mailing_id' => MAILING_ID, 'status' => 'Scheduled', 'scheduled_date' => date('YmdHis'), 'is_test' => 0, ); $new_job->create($params);// Save job in database
  4. Execute mailing job through code:
  5. CRM_Mailing_BAO_MailingJob::runJobs(); CRM_Mailing_BAO_MailingJob::runJobs_post();

Hope that will lead you towards your goal.

  • Thank you Hassan for your input ; I am not a programmer, but this may be useful. But my concern is about transfering my list of selected contacts from Drupal Views to a mailing list. Nov 8 '18 at 10:56
  • Sorry to talk in programming sense again, but i could think of doing this using PHP sessions. Through session in views as Views PHP field you can set session with variable containing info of selected contacts and use that session when creating mailing list. You would need this module for using php in views. drupal.org/project/views_php Nov 8 '18 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.