Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Custom Email Shows Keywords

    I've implemented code on the store side to send a custom email to the customer and a copy to an admin. The email is sent near the end of the order confirmation process and has been working well for years. I now need to send that email from the admin for certain orders when the order status has been updated to shipped instead of from the store side. I've set up an observer triggered at the end of the admin order status update code to set up the custom email and send it. I've used the same functions and defines on both the store and admin sides. But the email sent from the admin side consists of many email keywords instead of the desired text. The keywords appear to be what is expected for order status update emails including $EMAIL_TEXT_STATUS_UPDATED, $EMAIL_TEXT_STATUS_LABEL, through $EMAIL_TEXT_STATUS_PLEASE_REPLY.

    The email template for both the store side and admin side is "default". And $html_msg['EMAIL_MESSAGE_HTML'] and $html_msg['EMAIL_SUBJECT'] are set to what I want just prior to calling the zen_mail function in admin. Other data in the email included in the template, such as the store logo, copyright notice, spam notice, and disclosure notice, are sent correctly. It's just the email message and email subject that are incorrect.

    I'm stumped. What might be causing the email to not use the subject and message html data? What should I check?

    Dave

  2. #2
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Custom Email Shows Keywords

    When calling zen_mail() the 3rd parameter is the subject line, and the 8th parameter is the email template to use.
    What notifier hook is your observer attaching to? Do you mind posting your observer code?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Custom Email Shows Keywords

    DrByte,

    The notifier is NOTIFY_ADMIN_ORDERS_UPDATE_ORDER_END.
    The code is too long to post completely, but the observer code summary follows with the actual code of the function calling zen_mail following that. One of the products we sell is memberships to our organization. When the customer prefers to send a check or moneyorder for the order instead of using a credit card, we defer processing the order until we receive the payment. Payment receipt is indicated by setting the order status to "shipped" by an admin. Hence the need to perform some storefront processing in the admin.

    First, test to see if the order needs to be processed. If so, query the database to retrieve necessary data. Do some preliminary processing to formulate the email to admin staff. Then call functions to generate a new member number and next membership renewal date, save that data in the database, and set up and send an email to the customer. Finally finish up the email to admin staff and send it.

    Note that the email to the customer is html (in the current tests) and the email to the admin staff is text.

    The function to create and send the email to the customer is:
    Code:
    	function febt_send_customer_member_number($new_number) {
    		// input - $new_number: string containing new member number
    		// requires - $_SESSION['customer_id']
    		global $db;
    		// send email to customer with new number
    		// get email address
    		$query = $db->Execute("select customers_email_address, customers_lastname, customers_firstname from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
    		$email_text = NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_SALUTATION . $query->fields['customers_firstname'] . ",\n\n" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT1 . "\n\n" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT2 . $new_number . ". " . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT3 . "\n\n" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT4 . "\n\n";
    		$html_msg['EMAIL_SUBJECT'] = "<strong>" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_SUBJECT . "</strong><br /><br />";
    		$html_msg['EMAIL_MESSAGE_HTML'] = NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_SALUTATION . $query->fields['customers_firstname'] . ",<br /><br />" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT1 . "<br /><br />" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT2 . $new_number . ". " . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT3 . "<br /><br />" . NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_TEXT4;  
    		zen_mail($query->fields['customers_firstname'] . ' ' . $query->fields['customers_lastname'], $query->fields['customers_email_address'], NEW_MEMBER_NUMBER_NOTIFICATION_EMAIL_SUBJECT, $email_text, STORE_NAME, EMAIL_FROM, $html_msg);
    	}
    The message variables $html_msg and $email_text have been inspected and are correct. A portion of the email showing the template keywords follows.
    Name:  Screenshot 2024-08-13 at 7.50.59 AM.jpg
Views: 151
Size:  23.1 KB

    There are no errors in the log.

    Dave
    zc 1.5.7c

  4. #4
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Custom Email Shows Keywords

    I wonder if my problem is related to the admin email format setting which is set to "text"?

  5. #5
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Custom Email Shows Keywords

    Nope. Set admin email text format to html. Email to customer is unchanged. Email to admin staff is now html but instead of the text that was appearing, the email looks the same as the customer's email with all the template keywords. What is going on???

  6. #6
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Custom Email Shows Keywords

    I found that function zen_build_html_email_from_template is selecting 'email_template_order_status.html' instead of 'email_template_default.html', even though $module is 'default'. Don't know why.
    Dave

  7. #7
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Custom Email Shows Keywords

    Setting $current_page to NULL allowed function zen_build_html_email_from_template to find the correct email template. Problem solved.
    Dave

 

 

Similar Threads

  1. Custom keywords
    By provida in forum General Questions
    Replies: 0
    Last Post: 20 Dec 2010, 01:07 PM
  2. Custom keywords
    By josefs in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 28 Aug 2008, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg