• Resolved kennethrg

    (@kennethrg)


    Hi,

    Thanks for the great plugin. I notice that when sending an individual email (e.g. navigate to a contact detail page and click Send Email -> Compose), the “From” address defaults to the current user’s email address that’s stored in their profile. On my site, though, most of the time that is an offsite email address that my server does not have permission to use (e.g. it is a gmail.com address). Is this something I can change? I’d like to be able to set each user’s default “From” address to something other than their profile address.

    In my case, for example, jsmith is our president, and it would make sense for him to send mail from [email protected] instead of his personal [email protected]; but it doesn’t make sense to change his profile email address because he’s only president for a 2-year term after which he’d still want to use his account even though it wouldn’t be associated with [email protected].

    Alternatively, if Groundhogg could simply recognize that the profile address is offsite and exclude that as a valid “From” address, and default to a generic “From” address (e.g. [email protected]) that would make sense too.

Viewing 1 replies (of 1 total)
  • Plugin Author Adrian Tobey

    (@trainingbusinesspros)

    Hi Ken,

    I understand the usefulness of such a feature. We’ve added it to our feature requests board. There’s a lot of functionality in Groundhogg that is currently dependent on the user_email field, so changing it to a different field like gh_from_email all would be not be exactly super straightforward, at least not quickly.

    For now, a possible workaround might be a code snippet that you keep updated which hooks into the the PHPMailer function directly and swaps out the from email address at the last minute.

    For example…

    <?php

    /**
    * Swap out the from email address for specific emails.
    * This does not change the reply-to if set.
    *
    * @param $from_email
    *
    * @return mixed|string
    */
    function swap_from_email_address( $from_email ) {

    // make sure Groundhogg is active
    if ( ! defined( 'GROUNDHOGG_VERSION' ) ) {
    return $from_email;
    }

    // add additional mappings as needed
    $email_mappings = [
    '[email protected]' => '[email protected]',
    '[email protected]' => '[email protected]',
    ];

    // Check to see if the given from is in the email map
    if ( \Groundhogg\isset_not_empty( $email_mappings, $from_email ) ) {
    return $email_mappings[ $from_email ];
    }

    // if it's GMAIL or YAHOO or something.
    if ( \Groundhogg\is_free_email_provider( $from_email ) ) {
    // use the default from email instead
    return \Groundhogg\get_default_from_email();
    }

    return $from_email;
    }

    add_filter( 'wp_mail_from', 'swap_from_email_address', 9 ); // run before other hooks
    • This reply was modified 1 month, 3 weeks ago by Adrian Tobey.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.