Changing the From Email for GravityForms Notifications

Authored by

There are rare instances that you need to be able to programmatically make sure the from email is not set to a certain email.  Using the following filter will allow you to modify the From portion of the header before it sends. This code Snippet uses the fix_email snippet that can be found by clicking here.

add_filter( 'gform_pre_send_email', 'before_email_sent', 10, 4 );
function before_email_sent( $email, $message_format, $notification, $entry ) {
    // If GF logging is enabled, then it will record the a before an after of the email in the log.
    GFCommon::log_debug( __METHOD__ . '(): EMAIL BEFORE => ' . print_r( $email, true ) );
    $newEmail = 'correct@email.com';
    if ($newEmail != '') {
        // Check the Fix Email Function code snippet for what this does. It pretty much just changes the email within <> of the string.
        $updated_from = fix_email($email['headers']['From'], $newEmail); 
        $email['headers']['From'] = $updated_from; 
    }
    GFCommon::log_debug( __METHOD__ . '(): EMAIL AFTER => ' . print_r( $email, true ) );
    return $email;
}

 

Other Code Snippets

Change Permissions or Ownership of Files or Directories Recursively

Code Snippet | Linux

Sometimes when you are moving files from one host to another, you have to change the files owner or permissions so the web server can utilize it properly.

Read More
Find Files by Size

Code Snippet | Linux

Here is a Linux command line that searches for files that are over a certain size so that you can find where you might be able to free up some space. Useful to find error_logs that have run amok.

Read More
Import MySQL from Command Line

Code Snippet | Linux | MySQL

Here is a method to import a SQL file into a database via the Linux command line.

Read More
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram