Use Tags in From Email, From Name, and Reply To

Mattias

New Member
Hi, I am trying to hack the system a bit and insert tags from the list that will be the from email.reply to email, and from name. I have been able to remove the validation to the field to accept the tag in common/models/campaign.php but when I tested it it did not work. It did send the email but instead of parsing the tag content from the list it just showed the tag like [fromemail]@sendingdomain.com.

Do you know what files I will need to edit for this to work? Thanks!
 
Why would you need that, i mean, when creating a campaign, it inherits those values from the list anyway. Do you want to force some static tags to be used or the like ? Guess i'm trying to find out what you are after.
 
So this is the scenario. I have a company list that each contact is assigned to a sales rep. We want the message to come from the sales reps email/name instead of a generic company one.
 
Until I figure out a better way I am just going to use a list custom field and upload it with our list.
 
@Mattias - it's not an easy change...
The way i would do it is to add two hooks from an extension, like:
PHP:
// a small trick to make a global subscriber object , no worries, we unset it.
Yii::app()->hooks->addAction('console_command_send_campaigns_before_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $emailParams){
    if (!MW_IS_CLI) {
        return;
    }
    Yii::app()->params['__tmpSubscriberObj__' . $campaign->campaign_id .'__'. $subscriber->email] = $subscriber;
});
Yii::app()->hooks->addFilter('delivery_server_before_send_email', function($params, $server){
     if (!MW_IS_CLI || !($campaign = $server->getDeliveryObject()) || !is_object($campaign) || !($campaign instanceof Campaign)) {
         return $params;
     }
     
     if (!isset($params['to'])) {
         return $params; 
     }

     list($toEmail) = $server->getMailer()->findEmailAndName($params['to']);
     $key = '__tmpSubscriberObj__' . $campaign->campaign_id .'__'. $toEmail;
     $subscriber = isset(Yii::app()->params[$key]) ? Yii::app()->params[$key] : null;
     
     if (empty($subscriber)) {
        return $params;
     }
     unset(Yii::app()->params[$key]);
     
     $fromEmail  = $campaign->from_email;
     $searchReplace = CampaignHelper::getCommonTagsSearchReplace($fromEmail, $campaign, $subscriber);
     $fromEmail = str_replace(array_keys($searchReplace), array_values($searchReplace), $fromEmail);
     $params['from']  = array($fromEmail => $campaign->from_name);
     
     return $params;
});

So the above means you can have a from email in your campaign like [WHATEVER_TAG] and then when a campaign is being sent, that will be parsed with the actual value of the tag for your subscriber.
I haven't tested this, it's up to you from now on :)

Thanks.
 
Back
Top