Plain text in email notification not working


I know, this topic is not new, but the php script to change from html to text notifications does not work for me. There is a message: Cannot redeclare function change_notification_format.

What’s the problem?

add_filter( 'gform_notification', 'change_notification_format', 10, 3 );
function change_notification_format( $notification, $form, $entry ) {
     GFCommon::log_debug( 'gform_notification: change_notification_format() running.' );
    // Do the thing only for a notification with the name Text Notification
    if ( $notification['name'] == 'Text Notification' ) {
        GFCommon::log_debug( 'gform_notification: format changed to text.' );
        // Change notification format to text from the default html
        $notification['message_format'] = 'text';
    return $notification;

One more question:
I only want to change notifications with a name containing “text”. Could this work?

if (str_contains($notification['name'], 'text') !== false) {


That’s a standard PHP syntax error message which means you have added the same function twice. Something that PHP doesn’t allow.

If you want to use the snippet more than once in the same site you will want to change the function name both in the add_filter and function lines. e.g. from change_notification_format to change_notification_format_2

Ok, I see. Thanks! What about my second question? Would this works?

For the second question, that looks like it will work. Give it a try and tweak it if necessary.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.