The gform_mailgun_email filter allows you to modify the email arguments passed to the Mailgun API in Gravity Forms.
Usage
add_filter('gform_mailgun_email', 'modify_mailgun_email', 10, 5); function modify_mailgun_email($mailgun_email, $email, $message_format, $notification, $entry) { // your custom code here return $mailgun_email; }
Parameters
- $mailgun_email (array) – The Mailgun email arguments.
- $email (array) – The original email details.
- $message_format (array) – The message format, html or text.
- $notification (array) – The Notification object.
- $entry (array) – The current Entry object.
More information
See Gravity Forms Docs: gform_mailgun_email
Examples
Disable Mailgun Native Send
Disable native send for Mailgun, causing the email to be sent via the standard WordPress wp_mail function.
add_filter('gform_mailgun_email', 'disable_mailgun_native_send', 10, 5); function disable_mailgun_native_send($mailgun_email, $email, $message_format, $notification, $entry) { $mailgun_email['h:x-mailgun-native-send'] = false; return $mailgun_email; }
Add Custom Header
Add a custom header to the email being sent via Mailgun.
add_filter('gform_mailgun_email', 'add_custom_header', 10, 5); function add_custom_header($mailgun_email, $email, $message_format, $notification, $entry) { $mailgun_email['h:X-Custom-Header'] = 'My Custom Value'; return $mailgun_email; }
Modify Subject
Modify the email subject based on the entry data.
add_filter('gform_mailgun_email', 'modify_email_subject', 10, 5); function modify_email_subject($mailgun_email, $email, $message_format, $notification, $entry) { if ($entry['1'] == 'Special') { $mailgun_email['subject'] = 'Special Email: ' . $mailgun_email['subject']; } return $mailgun_email; }
Force Text Format
Force emails to be sent in text format instead of HTML.
add_filter('gform_mailgun_email', 'force_text_format', 10, 5); function force_text_format($mailgun_email, $email, $message_format, $notification, $entry) { $mailgun_email['text'] = strip_tags($mailgun_email['html']); unset($mailgun_email['html']); return $mailgun_email; }
Add CC Recipient
Add a CC recipient to the email being sent via Mailgun.
add_filter('gform_mailgun_email', 'add_cc_recipient', 10, 5); function add_cc_recipient($mailgun_email, $email, $message_format, $notification, $entry) { $mailgun_email['cc'] = '[email protected]'; return $mailgun_email; }