Send An Alert Email When Gravity Form Notifications Fail
A few times, I’ve been in a sticky situation after the Gravity Forms notifications stopped working without my knowledge.
In one instance, the client hadn’t received notifications from their enquiry form for over 2 months. Eeeek!
To avoid this from happening, I added the following function to my theme’s function.php file. Now, as soon as Gravity Forms is unable to send a notification to the recipient, the script triggers an email (to me).
add_action( 'gform_send_email_failed', function ( $error, $details, $entry ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
$to = 'your@email.com'; // Change this to your email address.
$subject = 'An Email Notification Error Occurred #'.$entry['id'];
$entryurl = get_home_url()."/wp-admin/admin.php?page=gf_entries&view=entry&id=".$entry['form_id']."&lid=".$entry['id'];
$body.= "Hi there,
this is an automated email to let you know that the notification for the following email did not get through to it's recipient.
Notification email '$details[subject]' for entry #$entry[id] failed.
";
$body = "Here is the link to the entry/issue $entryurl";
$toarr = array('your@email.com','yourbackup@email.com'); // Change these email addresses to the recipients.
foreach($toarr as $tonew)
{
wp_mail( $tonew, $subject, $body );
}
}, 10, 3 );