Jump to content

"from address" in admin:order received template


cpierrep
 Share

Recommended Posts

Hi all

In the admin email received notifying me of a new order, the email comes from the store email address, which is specified in "Store Settings, Advanced". In the previous version of CC we used, we edited a template/form somewhere (excuse the vagueness but I cannot remember where!) to allow us to specify the "from email address" as being that of the customer, so that we could easily "reply" on that email rather than copying and pasting the email address.

Is there a way in CC6 to do this? - I cannot change the "sender's email address" in Store Settings, Advanced" as that would of course be a store-wide change affecting all templates which use the store email address.

 

thanks

Link to comment
Share on other sites

OK!! Success at last....:D

I mentioned above that I would prefer to have the "New Order Received" email which is sent to the admin, to have the client's email address as the "from" address, rather than the default store address. We have now been able to get this done in the following manner - there may be easier ways, but this is what we did. (And, as always, make sure you have a backup of your existing files!)

Open mailer.class.php

find the following line: (in mine it is line 147)

                 public function sendEmail($email = false, $contents = false, $template_id = false) 

amend the line to read:

                 public function sendEmail($email = false, $contents = false, $template_id = false, $CHRIS_FROM_EMAIL="", $CHRIS_FROM_NAME=""

Please note that the CHRIS_FROM_EMAIL and CHRIS_FROM_NAME can of course have other names, just be sure to use the same ones throughout!


Find the following code (mine was in line 202-204)

            if (isset($contents['email'])) {
                $this->addReplyTo($contents['email'], (isset($contents['from'])) ? $contents['from'] : '');
            }


add in/amend after this:


            if($CHRIS_FROM_EMAIL=="")
            {
                $this->Sender = $GLOBALS['config']->get('config', 'email_address');
            }
            else
            {
                $this->Sender = $CHRIS_FROM_EMAIL;
                $this->From = $CHRIS_FROM_EMAIL;
                $this->FromName = $CHRIS_FROM_NAME;
            }


save the file


Open order.class.php


find the following code (mine was line 401-402):  (this is for Order pending email sent to admin)

        if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
            $this->assignOrderDetails(null, true);            

amend the next two lines (in my case 403/404) to the read as follows:  

        $CHRISTEMP =  $order_summary['first_name'] . " " . $order_summary['last_name'];
        $admin_mailer->sendEmail($admin_notify, $content, false, $order_summary['email'], $CHRISTEMP  );

find the following code (mine was line 436-437): (this is for Order process New Order received email sent to admin)

        if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
            $this->assignOrderDetails(null, true);

amend the next two lines (in my case 438/439):

        $CHRISTEMP =  $order_summary['first_name'] . " " . $order_summary['last_name'];
        $admin_mailer->sendEmail($admin_notify, $content, false, $order_summary['email'], $CHRISTEMP  );

Save the file

 

The admin email should now come as being from the client's email address

Link to comment
Share on other sites

WOW!! I'm glad you found a way to get what you want. But please remember that any edits you make to core code will be lost on the next upgrade. I always comment before and after any edits, so I can merge them into the new version. I use BeyondCompare, but there are other good file difference programs available that make merging versions easier.

Link to comment
Share on other sites

Keeping in mind the above caution:

Personally, I do not like the situation where an email is originated from my_domain.com, but the From: address says it is coming from some_where_else.com.

However, I realize this happens all the time. I've done it myself. But I also realize that, to combat fraud and phishing, efforts have been and are being developed to stop this impersonation.

Therefore, I recommend that the admin notices of new orders keep the From: address as the store's email address, and use the ReplyTo: field to hold the customer's email address. Almost all email programs will indicate the presence of, and use by default, this ReplyTo address when the reader is making a reply.

In the admin template settings.index.php, near line 347, find:

   <div id="Advanced_Settings" class="tab_content">
      <h3>{$LANG.settings.title_advanced}</h3>
      <fieldset>
         <legend>{$LANG.common.email}</legend>
         <div><label for="email_method">{$LANG.settings.email_method}</label><span><select name="config[email_method]" id="email_method" class="textbox">

Change to:

   <div id="Advanced_Settings" class="tab_content">
      <h3>{$LANG.settings.title_advanced}</h3>
      <fieldset>
         <legend>{$LANG.common.email}</legend><div><label for="customer_reply_to">Use Customer's address in Reply-To:</label><span><input name="config[customer_reply_to]" id="customer_reply_to" type="hidden" class="toggle" value="{$CONFIG.customer_reply_to}"></span></div>
         <div><label for="email_method">{$LANG.settings.email_method}</label><span><select name="config[email_method]" id="email_method" class="textbox">

In the file /classes/order.class.php, near line 401 (and 435), find:

					if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
						$this->assignOrderDetails(null, true);
						$admin_mailer->sendEmail($admin_notify, $content);
						$GLOBALS['session']->set($message_id, true, 'email');
						unset($content);
					}

Change to:

					if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
						$this->assignOrderDetails(null, true); if($GLOBALS['config']->get('config','customer_reply_to')) { $content['email'] = $order_summary['email']; $content['from'] = $order_summary['first_name']." ".$order_summary['last_name']; }
						$admin_mailer->sendEmail($admin_notify, $content);
						$GLOBALS['session']->set($message_id, true, 'email');
						unset($content); $admin_mailer->clearReplyTos;
					}

Near line 435, make the exact same change.

The new code is on the same lines as existing code only so that the line numbers do not change.

The Mailer will look in the $content array for 'email' and 'from' keys to set the ReplyTo field of the email. After sending, it is important to clear out the ReplyTo field (due to the way the Mailer class is instantiated).

There is a new admin setting in Store Settings, Advanced tab to enable or disable this feature.

Link to comment
Share on other sites

Many thanks for this @bsmither it works a treat.  That will be really useful for me, much appreciated.

Whilst tinkering with this I noticed that in my sent messages I was getting a line "message from Boo's Hand Crafted Jewellery" butted immediately before where I'd typed the recipients name at the beginning of my reply - I'd seen it in a message I'd received from another shop as a customer and thought it odd at the time.  Turns out I was doing it too.

This turned out to be the TITLE of the default e-mail template, which doesn't show up until the message has been sent.  I've removed it and it has resolved that issue, but there seem to be a lot of irritations to the e-mail templates.

The Contact Form uses the reply to function for the sender's entered e-mail address, so it seems it would be useful to add this to the email templates you might reply to as well.  It's these tiny details that make your shop and business look that bit more slick.

Link to comment
Share on other sites

  • 4 months later...

This has worked like a charm for me, however there is one more thing i'm missing.

I would also like the mail I (the admin) recieve to show the customer's name as the sender.

This makes it easier for me to see which mail is what in the long list of orders. Now all the mail just show Our company name and i still have to open them to see who it's from.

Any way to do this?

Link to comment
Share on other sites

There is a way, but what you ask has some consequential concerns.

If, for whatever weird reason, an email sent by the store to your master email address bounces. The non-delivery notice may get sent to the customer. Confusing.

Because spammers send emails "from" a spoofed address, security blocks have been created to trash such emails. (I run an email server. This is a default setting.)

So, again, we can do this. Nothing is stopping us from providing CubeCart's email with a "from" address that is not yours. But do not expect success. Let us know if you really want to try it.

However, you may want to try this strategy: create another administrator with a separate email address that you own, and set it to "Receive order notifications". We can then remove the store's master email from being given to the mailer for the admin's New Order email. This should satisfy your need to somehow segregate these emails. Plus, we can add the customer's name into the Subject field. The "Reply-To" will still work.

Link to comment
Share on other sites

Hi Patrickm81

The edits I listed above op 17 July works for me in terms of displaying the email as coming from the client rather than the store email address. 

I do not take issue with Bsmither's comments that using it the way I outlined may lead to an email being blocked by some email servers - it is quite correct that mail hosters/isp's put into place policies to stop this "impersonation". But I must also say that in all the time I've had that particular edit running (5 months with CC6, much more with a previous version), and with hundreds of store orders, I've not had one block take place (to my knowledge in any case, as no client has indicated that they've placed an order for which I did not get an admin email). Maybe I've just been *lucky* with the vps I run!

I can only say this has worked very well for me. 

Colin

 

Link to comment
Share on other sites

  • 1 month later...
On 7/19/2016 at 7:52 PM, bsmither said:

In the file /classes/order.class.php, near line 401 (and 435), find: if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) { $this->assignOrderDetails(null, true); $admin_mailer->sendEmail($admin_notify, $content); $GLOBALS['session']->set($message_id, true, 'email'); unset($content); } Change to: if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) { $this->assignOrderDetails(null, true); if($GLOBALS['config']->get('config','customer_reply_to')) { $content['email'] = $order_summary['email']; $content['from'] = $order_summary['first_name']." ".$order_summary['last_name']; } $admin_mailer->sendEmail($admin_notify, $content); $GLOBALS['session']->set($message_id, true, 'email'); unset($content); $admin_mailer->clearReplyTos; } Near line 435, make the exact same change.

I need help trying to merge the 6.1.5 changes in where unset($content) is in your tweak to get ReplyTo

Link to comment
Share on other sites

What you may already have:

if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
 $this->assignOrderDetails(null, true);
 if($GLOBALS['config']->get('config','customer_reply_to')) {
  $content['email'] = $order_summary['email'];
  $content['from'] = $order_summary['first_name']." ".$order_summary['last_name'];
 }
 $admin_mailer->sendEmail($admin_notify, $content);
 $GLOBALS['session']->set($message_id, true, 'email');
 unset($content);
 $admin_mailer->clearReplyTos;
}

To put a change from CC615 into place:

if (!$GLOBALS['session']->has($message_id, 'email') && ($content = $admin_mailer->loadContent('admin.order_received')) !== false) {
 $this->assignOrderDetails(null, true);
 if($GLOBALS['config']->get('config','customer_reply_to')) {
  $content['email'] = $order_summary['email'];
  $content['from'] = $order_summary['first_name']." ".$order_summary['last_name'];
 }
 $admin_mailer->sendEmail($admin_notify, $content);
 $GLOBALS['session']->set($message_id, true, 'email');
 $admin_mailer->clearReplyTos;
}
unset($content);

 

Link to comment
Share on other sites

I actually like BSmither;s option. If an email comes from your site then it needs to be your store email. If for convenience sake, we need the reply address to be the customer's, then its understandable. Ideally, we should have the original email  sent to the customer to be "cc'd" to the admin. This way a "reply-all" would cover it.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...