1

This question already has an answer here:

I am trying to create a scheduled mailing through the CiviCRM API.

Here's my code:

$params = array(
    'sequential'         => 1,
    'created_id'         => $contact_id, 
    'created_date'       => date('Y-m-d H:i:s'),
    'scheduled_id'       => $contact_id,
    'scheduled_date'     => date('Y-m-d') . ' 11:00:00',
    'approver_id'        => $contact_id,
    'approval_date'      => date('Y-m-d H:i:s'),
    'approval_status_id' => 1,
    'msg_template_id'    => 214,
    'subject'            => 'Test Subject',
    'name'               => 'Test Email Title',
    'body_html'          => <p>Test Email Body</p>,
    'body_text'          => 'Text email body',
    'groups'             => array(
      'include' => array($group_id),
      'exclude' => array(),
    ),
    'mailings'           => array(
      'include' => array(),
      'exclude' => array(),
    ),
    'from_name'          => "Test Sender",
    'from_email'         => "test_sender@test_sender.com",
    'replyto_email'      => "test_sender@test_sender.com",
    'reply_id'           => 8,  
    'unsubscribe_id'     => 5,  
    'optout_id'          => 7,  
    'resubscribe_id'     => 6,  
    'footer_id'          => 2,  
    'header_id'          => 1,  
    'open_tracking'      => 1,
  );    

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

I've managed to create the schedule mailing without problems and I don't receive any errors when it gets sent. But when I view the send report, the email is sent to zero recipients.

Upon some investigation I noticed non of my recipients are being added to the civicrm_mailing_recipients table and I'm guessing that's why no one is getting any emails.

I'm wondering if I'm missing something, I'm assuming the API should be adding those contacts in the group I'm including to the civicrm_mailing_recipients table, why else have this feature?

When researching I found this thread: https://forum.civicrm.org/index.php/topic,24075.0.html

Thanks.

marked as duplicate by Jon G - Megaphone Tech, William Mortada, Community Feb 8 '17 at 13:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.