1

I'm trying to create a mailing based on a template through the CiviCRM API.

Here's my code:

$params = array(
  'name' => $subject,
  'msg_template_id'=> 87,
  'created_id' => 1,
  'header_id' => 1,
  'footer_id' => 17,
  'from_email' => $from,
  'groups' => array(
    'include' => array(
      '0' => 893,
     ),
  ),
  'mailings' => array(
    'include' => array(),
    'exclude' => array(),
  ),
  'options' => array(
    'force_rollback' => 1,
  ), 
  'api.mailing_job.create' => 1, 
  'api.MailingRecipients.get' => array(
    'mailing_id' => '$value.id',
    'api.contact.getvalue' => array(
      'return' => 'display_name',
    ),
    'api.email.getvalue' => array(
      'return' => 'email',
    ),
  ),
);

$result = civicrm_api3('Mailing', 'create', $params);

In mailing everything is correct, the template chosen in the settings is the correct one. But there is no content in the mail.

How to make the content of the mail automatically filled by the content of the template and not from the body_html parameter?

1 Answer 1

2

We are using a separate API call to retrieve the required parameters for subject, body_html and body_text:

$result = civicrm_api3('MessageTemplate', 'getsingle', array(
   'id' => 87,
 ));

You could use API chaining with Mailing.create but I don't see a huge benefit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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