1

I'm using the API to send a bulk email each week to all our members. This is the code: $currentTime = new DateTime(); $approval_date = $currentTime->format('Y-m-d H:i:s'); $currentTime->add(new DateInterval('PT1H')); $schedule_date = $currentTime->format('Y-m-d H:i:s');

$params = [
    'scheduled_date' => $schedule_date,
    'approver_id' => 396,
    'approval_date' => $approval_date,
    'from_name'          => "Jack Donohue",
    'from_email'         => "info@crw.org",
    'replyto_email'      => "donohue.jack@gmail.com",
    'subject' => $subject,
    'body_text' => $text,
    'body_html' => $html,
    'name' => 'weekly email',
    'created_id' => 396,
    'header_id' => '',
    'footer_id' => '',
    'groups' => [
        'include' => [
            '0' => 128,     // Current members
        ],
        'exclude' => [
        ],
    ],
    'mailings' => [
        'include' => [],
        'exclude' => [],
    ],
    /*
    'options' => [
        'force_rollback' => 0,
    ],
    */
    'api.MailingRecipients.get' => [
        'mailing_id' => '$value.id',
        'api.contact.getvalue' => [
            'return' => 'display_name',
        ],
        'api.email.getvalue' => [
            'return' => 'email',
        ],
    ],
];

try{
    $result = civicrm_api3('Mailing', 'create', $params);
}
catch (CiviCRM_API3_Exception $e) {
    // Handle error here.
    $errorMessage = $e->getMessage();
    $errorCode = $e->getErrorCode();
    $errorData = $e->getExtraParams();
    log_message( $errorMessage);return;
}

The email is created, scheduled to be sent, and is sent, but the report says it was sent to 0 recipients

Delivery Summary Intended Recipients 2417
Successful Deliveries 0 (0.00%)

The only thing that looks odd is that the Sent By field in the table of emails is empty despite the fact that I set this in the parameters.

It's supposed to be sent out around 2 am each Thursday, and when it isn't I do reuse and send it manually which works fine.

Can you figure out what I am doing wrong?

Thanks,

Jack Donohue

Your Answer

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

Browse other questions tagged or ask your own question.