$emailId = $emailDetail[$email]['email_id'];
$contactId = $emailDetail[$email]['contact_id'];
}
- if (!$contactId) {
+ if (!$contactId && CRM_Core_Permission::check('add contacts')) {
//create new contact.
$contact = civicrm_api3('Contact', 'create',
[
$contactId = $contact['id'];
$emailId = $contact['values'][$contactId]['api.Email.get']['id'];
}
- civicrm_api3('MailingEventQueue', 'create',
- [
- 'job_id' => $job['id'],
- 'email_id' => $emailId,
- 'contact_id' => $contactId,
- ]
- );
+ if ($emailId && $contactId) {
+ civicrm_api3('MailingEventQueue', 'create',
+ [
+ 'job_id' => $job['id'],
+ 'email_id' => $emailId,
+ 'contact_id' => $contactId,
+ ]
+ );
+ }
}
}