The gform_postmark_send_email_failed action event is triggered when an email from Gravity Forms fails to be passed to Postmark.
Usage
add_action('gform_postmark_send_email_failed', 'my_function', 10, 6);
Parameters
- $error_message (string) – The error message.
- $postmark_email (array) – The Postmark 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_postmark_send_email_failed
Examples
Log email failure message
Log the email failure message when the email fails to be passed to Postmark.
function log_email_failure($error_message, $postmark_email, $email, $message_format, $notification, $entry) {
// Log the error message to a custom log file
error_log($error_message, 3, "/path/to/your/error.log");
}
add_action('gform_postmark_send_email_failed', 'log_email_failure', 10, 6);
Send a notification to admin on email failure
Send an email to the admin when an email fails to be passed to Postmark.
function notify_admin_on_failure($error_message, $postmark_email, $email, $message_format, $notification, $entry) {
// Send a notification email to the admin
wp_mail(get_option('admin_email'), 'Email Failed', 'Email failed to be passed to Postmark: ' . $error_message);
}
add_action('gform_postmark_send_email_failed', 'notify_admin_on_failure', 10, 6);
Update entry meta on email failure
Update the entry meta to store the failure reason when the email fails to be passed to Postmark.
function update_entry_on_failure($error_message, $postmark_email, $email, $message_format, $notification, $entry) {
// Update the entry meta with the error message
gform_update_meta($entry['id'], 'email_failure_reason', $error_message);
}
add_action('gform_postmark_send_email_failed', 'update_entry_on_failure', 10, 6);
Retry sending the email
Retry sending the email when it fails to be passed to Postmark.
function retry_sending_email($error_message, $postmark_email, $email, $message_format, $notification, $entry) {
// Check if we have already retried sending the email
if (empty($postmark_email['headers']['X-Retry'])) {
// Add a header to indicate that we are retrying
$postmark_email['headers']['X-Retry'] = '1';
// Send the email again
GFCommon::send_email($postmark_email['to'], $postmark_email['subject'], $postmark_email['message'], $postmark_email['headers'], $postmark_email['attachments'], $postmark_email['message_format'], $postmark_email['from'], $postmark_email['from_name']);
}
}
add_action('gform_postmark_send_email_failed', 'retry_sending_email', 10, 6);