Forums / General Questions / How to Create an additional Custom Email?

How to Create an additional Custom Email?

Locked
Results 1 to 20 of 31
This thread is locked. New replies are disabled.
05 Oct 2009, 18:39
#1
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

How to Create an additional Custom Email?

Hi,

Our company uses Paypal for processing all of our orders online. We have 2 company names under one Paypal account e.g Company A and B under Paypal account Company A.

Whenever a customer buys from Company B, they get charged on their credit card under Company A and we are getting problems of disputes from customers who think they are getting unauthorized charges.

Anyway, we were thinking of creating a custom email that comes after order confirmation that says their credit card was charged under the name "Company A" so that they know beforehand what to expect on their credit card charged.

Rather than adding the information as a comment (which we have done but have not successfully helped in reducing disputes), we want a separate email sent out.

How do we go about doing this? Does this entail extensive code modification?

Any help towards the first step would be greatly appreciated.
05 Oct 2009, 18:44
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

The existing order-confirmation emails are sent via send_order_emails() inside the /includes/classes/order.php class.
You could add your own code to send yet another email after the existing ones are sent, perhaps using the simple low-stock email code near the beginning of that section as an example.
05 Oct 2009, 19:25
#3
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Thank you DrByte. I have looked at order.php codes and have tracked the low stock email to about line 900:

if ($this->email_low_stock != '' and SEND_LOWSTOCK_EMAIL=='1') {
// send an email
$email_low_stock = SEND_EXTRA_LOW_STOCK_EMAIL_TITLE . "\n\n" . $this->email_low_stock;
zen_mail('', SEND_EXTRA_LOW_STOCK_EMAILS_TO, EMAIL_TEXT_SUBJECT_LOWSTOCK, $email_low_stock, STORE_OWNER, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => nl2br($email_low_stock)),'low_stock');
}

Is this what I would be replicating? and I suppose there has to be a corresponding html template for the new email? e.g email_template_lowstock.html

Are these just the two files I will be messing with? or are there more that should be created?

DrByte:

The existing order-confirmation emails are sent via send_order_emails() inside the /includes/classes/order.php class.
You could add your own code to send yet another email after the existing ones are sent, perhaps using the simple low-stock email code near the beginning of that section as an example.
05 Oct 2009, 21:16
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Yes, that's the example to follow.

Basically I'd do this:
  zen_mail($this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], EMAIL_SUBJECT_CC_MSG, EMAIL_TEXT_CC_MSG, STORE_OWNER, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => nl2br(EMAIL_TEXT_CC_MSG)),'ccnotice');
and then in a new language file (ie: /includes/languages/english/extra_definitions/my_cc_msg_text.php ) define the text you want in the emails:
<?php
define('EMAIL_SUBJECT_CC_MSG', 'An important note about your recent purchase.');
define('EMAIL_TEXT_CC_MSG', 'Thank you for your recent purchase at ' . STORE_NAME . '.' . "\n\n" . 'We are sending you this message to advise you that your purchase will show up on your credit card statement as "ABCDEFG COMPANY" (our sister company) instead of "' . STORE_NAME . '".  Please make note of this when reviewing your credit card bill. Thank you for your understanding, and we apologize for any confusion this may cause.' . "\n\n" . 'We look forward to you visiting our online store again.');


Or use the attached files to make it simpler:
06 Oct 2009, 12:55
#5
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Dr. Byte thank you! This works out great! I have another question though, how to do I make it so that we are also copied on the notice?

Thanks again in advance!! :clap:
06 Oct 2009, 17:49
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Decostyle:

Dr. Byte thank you! This works out great! I have another question though, how to do I make it so that we are also copied on the notice?

Thanks again in advance!! :clap:

Are you sure you really want a bunch of duplicates of those emails? They'll all be identical.

I suppose you might use it as an audit trail, but I can't see that winning a chargeback case alone. I suppose it might be one of many resources that could win it.
If you really want a copy, run the zen_mail call again (copy it onto the next line), but change the first 2 parameters to STORE_OWNER and STORE_OWNER_EMAIL_ADDRESS respectively, so that it sends to you instead.
06 Oct 2009, 19:18
#7
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Actually, I was looking at the email as sort of CC where I can see and make sure that the email was sent to the customer and have it on record. I believe using the code you suggested won't show the customer name that it was originally sent to?
06 Oct 2009, 19:22
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Decostyle:

I believe using the code you suggested won't show the customer name that it was originally sent to?

True enough.

You could alter it to include the customer's name and email address inside the actual body of the email.

There's no built-in support for cc/bcc in emails in v1.3.8a or earlier.
06 Oct 2009, 19:26
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Or ... you could change the core code to add bcc support specifically for this email message, similar to how I suggested it to someone here: http://www.zen-cart.com/forum/showpost.php?p=597726&postcount=2

You'd have to make a few alterations to that suggested code, like this:
      $mail->Subject  = $email_subject;

      if [COLOR="Indigo"]($module == 'ccnotice') {
        $mail->AddBCC(STORE_OWNER_EMAIL_ADDRESS, STORE_NAME);
      }[/COLOR]
      
      $mail->From     = $from_email_address;
07 Oct 2009, 13:02
#10
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Hello Dr. Byte,

I have read through your other post and have this on my functions_email.php:

if (IS_ADMIN_FLAG === true && $module == 'ccnotice') {
$mail->AddBCC(STORE_OWNER_EMAIL_ADDRESS, STORE_NAME);
}


Tried it and customer gets the cc notice but the store owner email address does not get the bcc. Is it because the 'ccnotice' is not a module?
07 Oct 2009, 17:29
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

If you notice, the example I posted above specifically leaves out the IS_ADMIN_FLAG === true
Why did you add it back in?
07 Oct 2009, 17:32
#12
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Hi Dr. Byte, I added it back because when I used your code as-is, it gave me a blank page.
07 Oct 2009, 17:36
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Then you must have made a typo.
The admin-flag part will cause it to not run, so I'm not surprised it didn't work when you added it.
07 Oct 2009, 17:42
#14
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Ok so I took it out and now have this code:

$mail->Subject = $email_subject;

if ($module == 'ccnotice') {
$mail->AddBCC(STORE_OWNER_EMAIL_ADDRESS, STORE_NAME);
}


$mail->From = $from_email_address;


And I get this error:

Email Error: Could not instantiate mail function. Please check Admin->Configuration->Email Options->Email Transport.

I'm testing on local host computer to test. If I add the admin flag then it works.

Really don't know why this error is happening? Please help! Thanks!!
07 Oct 2009, 17:48
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Testing email on localhost computer probably gives you that error on ALL email messages, doesn't it?
07 Oct 2009, 17:54
#16
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

Nope, all my emails are going out normally testing on localhost. I get confirmations emails etc. Except for when I added that code bit on BCC then that is when I started to get that error. When I take the code out, it works fine. When I add the Admin flag in, it works fine...
07 Oct 2009, 18:06
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

In Admin->Configuration->Email Options, what do you have set for the "Store Owner Email Address" option? How does that compare with the rest of the email addresses listed on that screen?
07 Oct 2009, 18:09
#18
decostyle avatar

decostyle

Zen Follower

Join Date:
Mar 2008
Posts:
336
Plugin Contributions:
0

Re: How to Create an additional Custom Email?

They are all [email protected], I get all of our test mails using the local host in my local mail set up for that account. I have mercury mail set up.

Will the coding only work on a live site then?
07 Oct 2009, 18:12
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Shouldn't be any difference on local vs live.
07 Oct 2009, 18:29
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: How to Create an additional Custom Email?

Hmmm ... looking back at the define() for EMAIL_TEXT_CC_MSG I had given you earlier ... Go in and change the "We're" to "We are" (ie: remove the extra ' in there, as it causes a syntax error)