The gform_sendgrid_email filter allows you to modify the email being sent by SendGrid.
Usage
add_filter('gform_sendgrid_email', 'your_function_name', 10, 5);
Parameters
- $sendgrid_email (array): The SendGrid email arguments.
- $email (array): The original email details.
- $message_format (string): The message format, either ‘html’ or ‘text’.
- $notification (Notification Object): The Notification object.
- $entry (Entry Object): The current entry.
More information
See Gravity Forms Docs: gform_sendgrid_email
Examples
Add a CC email address
add_filter('gform_sendgrid_email', 'change_sendgrid_email', 10, 5);
function change_sendgrid_email($sendgrid_email, $email, $message_format, $notification, $entry) {
$sendgrid_email['personalizations'][0]['cc'][0]['email'] = '[email protected]';
return $sendgrid_email;
}
Change the “from” email address
add_filter('gform_sendgrid_email', 'update_from_email', 10, 5);
function update_from_email($sendgrid_email, $email, $message_format, $notification, $entry) {
$sendgrid_email['from']['email'] = '[email protected]';
return $sendgrid_email;
}
Add a BCC email address
add_filter('gform_sendgrid_email', 'add_bcc_email', 10, 5);
function add_bcc_email($sendgrid_email, $email, $message_format, $notification, $entry) {
$sendgrid_email['personalizations'][0]['bcc'][0]['email'] = '[email protected]';
return $sendgrid_email;
}
Change the email subject
add_filter('gform_sendgrid_email', 'update_email_subject', 10, 5);
function update_email_subject($sendgrid_email, $email, $message_format, $notification, $entry) {
$sendgrid_email['subject'] = 'New Subject for the Email';
return $sendgrid_email;
}
Modify the email content
add_filter('gform_sendgrid_email', 'update_email_content', 10, 5);
function update_email_content($sendgrid_email, $email, $message_format, $notification, $entry) {
$sendgrid_email['content'][0]['value'] = 'This is the new email content.';
return $sendgrid_email;
}