The gform_sendgrid_send_email_failed action is triggered when an email from Gravity Forms fails to be passed to SendGrid.
Usage
add_action('gform_sendgrid_send_email_failed', 'my_function', 10, 6);
Parameters
- $error_message (string) – The error message.
- $sendgrid_email (array) – The SendGrid email arguments.
- $email (array) – The original email details.
- $message_format (array) – The message format, either html or text.
- $notification (array) – The Notification object.
- $entry (array) – The current Entry object.
More information
See Gravity Forms Docs: gform_sendgrid_send_email_failed
Examples
Log failed email errors
Log the error messages when emails fail to send.
add_action('gform_sendgrid_send_email_failed', 'log_failed_email_errors', 10, 6);
function log_failed_email_errors($error_message, $sendgrid_email, $email, $message_format, $notification, $entry) {
// Log the error message
error_log("Email failed to send: " . $error_message);
}
Send a notification on failed email
Send an admin notification when an email fails to be sent.
add_action('gform_sendgrid_send_email_failed', 'send_admin_notification_on_failed_email', 10, 6);
function send_admin_notification_on_failed_email($error_message, $sendgrid_email, $email, $message_format, $notification, $entry) {
// Compose the email message
$admin_email = '[email protected]';
$subject = 'Email failed to send';
$message = "An email failed to send. Error message: " . $error_message;
// Send the email
wp_mail($admin_email, $subject, $message);
}
Update entry meta on email failure
Update entry meta to indicate that an email failed to send.
add_action('gform_sendgrid_send_email_failed', 'update_entry_meta_on_email_failure', 10, 6);
function update_entry_meta_on_email_failure($error_message, $sendgrid_email, $email, $message_format, $notification, $entry) {
// Update the entry meta
gform_update_meta($entry['id'], 'email_failed', $error_message);
}
Retry sending failed email
Retry sending the email when it fails to send.
add_action('gform_sendgrid_send_email_failed', 'retry_failed_email', 10, 6);
function retry_failed_email($error_message, $sendgrid_email, $email, $message_format, $notification, $entry) {
// Retry sending the email
wp_mail($email['to'], $email['subject'], $email['message'], $email['headers'], $email['attachments']);
}