I have a form that sends a notification on a custom event. The form data is submitted via PHP and GFAPI, so there is no actual file upload, and I add the attachment (an ICS file) to the notification using the “gform_notification” filter. The ICS file works and is attached to the notification email, but for some reason there are TWO ICS files attached even though I only attached one. Here is my code for submitting the form and attaching the file.
$gform_id = 13;
$input_values = array(
'input_1' => $fn,
'input_18' => $ln,
'input_4' => $email,
'input_19' => $registrant_id,
'input_20' => $registrant_status,
'input_5' => $webinar_id,
'input_6' => $google_link,
'input_10' => $topic,
'input_11' => $join_link,
'input_12' => $outlook_link,
'input_13' => $yahoo_link,
'input_21' => $ics_file_name,
'input_16' => $start->format('M j, Y'),
'input_17' => $start->format('g:i A (T)')
);
$result = GFAPI::submit_form($gform_id, $input_values);
if($result['is_valid']) {
$entry_id = $result['entry_id'];
$gEntry = RGFormsModel::get_lead($entry_id);
$edit_link = 'https://example.com/edit?id='.$entry_id;
$gEntry[15] = $edit_link;
$updated = GFAPI::update_entry($gEntry);
if($updated) {
//Send the notification
$gForm = GFAPI::get_form($gform_id);
GFAPI::send_notifications($gForm, $gEntry, 'webinar_registered');
}
}
add_filter('gform_notification', 'add_ics_attachment', 10, 3);
function add_ics_attachment($notification, $form, $entry) {
if($form['id'] == 13 && $notification['name'] == 'Send Confirmation Email') {
$webinar_id = $entry[5];
$notification['attachments'] = ['/var/www/example.com/ics/webinar_'.$webinar_id.'.ics'];
}
return $notification;
}
Because there is no file upload field, I enabled attachments manually for the notification by going into the database and changing the “enableAttachments” setting to “true”. The email is sent out via a plugin that connects to the Google SMTP server. Any ideas on why it is attaching 2 ICS files instead of just the one? Both files are identical, but one has the name I gave it and the other is called “Mail_Attachment.ics”.