AI Summary
Description
The wpforms_emails_mailer_get_attachments
filter lets you add or modify file attachments for email notifications. By default, WPForms includes uploaded files, but you can use this filter to attach custom files such as PDFs, terms sheets, or other documents.
This filter is useful when you want every notification email to include a specific file or when adding conditional attachments based on the form ID or submission data. The paths must be valid server file paths, not just URLs.
parameter | type | description |
---|---|---|
$attachments | string | List of file paths to attach. |
$mailer | Mailer | The Mailer instance for the current email. |
Source
wpforms/src/Emails/Mailer.php
Example
// Attach a PDF terms sheet to a specific form (ID 42).
function wpf_dev_attach_terms_pdf( $attachments, $mailer ) {
$form_id = $mailer->get( 'form_data' )['id'] ?? 0;
if ( $form_id === 42 ) {
$attachments[] = WP_CONTENT_DIR . '/uploads/terms.pdf';
}
return $attachments;
}
add_filter( 'wpforms_emails_mailer_get_attachments', 'wpf_dev_attach_terms_pdf', 10, 2 );