Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
I have an order form where a list of about 20-30 products are stored in a repeatable region. Customers enter quantities for the items they want and when they submit the form, it sends an email to the site owner and redirects to a thank you page that summarizes the order. There's no payment involved.

The issue I'm having is with white space in the generated email. I loop through the repeatable region, displaying products that have been ordered and calculating totals while ignoring those that haven't. This leaves a lot of extraneous newlines with each iteration of the loop. It doesn't matter on an html page, but in the text email each newline and indentation is faithfully reproduced, leaving big gaps in the email.

I'm wondering if there is any way of managing the white space created while generating the content of the send_mail tag. To complicate the matter, I want to leave intentional line breaks while removing extraneous ones. I suppose I could enable html in the send_mail tag to create a clean format, but I'd prefer to send plain text. I worry (maybe unnecessarily) about spam and junk filters looking askance at the html when replying to customers' orders.
Hi Tim,

The white-spaces within <cms:send_mail> block getting outputted into the mail, normally make it easier to compose text emails because what you see in the template's source code is what gets sent eventually.

With dynamically generated mail body, however, as in your case, I can see how this could prove to be problematic.

The solution would be to craft the dynamic content *outside* the cms:send_mail block stuffing it into a variable, and then use the fully created content inside the mail body by using the single variable.

As an example -
Code: Select all
<cms:show_repeatable 'whatever' >
    <cms:set my_mail_body = "<cms:show my_mail_body /> <cms:show whatever_field />" 'global' />
</cms:show_repeatable> 

or
Code: Select all
<cms:show_repeatable 'whatever' >
<cms:capture into='my_mail_body' 'global' ><cms:show my_mail_body />
<cms:show whatever_field />
</cms:capture>
</cms:show_repeatable>

where in the code above we are using cms:set or cms:capture to concatenate values from the repeatable region into a single variable (you can tweak the code to control how many newlines or space characters get introduced between two values).

We then use the variable in the mail as follows -
Code: Select all
<cms:send_mail ..>
Hi Peter,

Following is a summary of your order:
<cms:show my_mail_body />
</cms:send_mail>

Does this help?
Yes. That's exactly the help I needed. My own case is a little more complicated, with conditional statements, variables, and calculations mixed in, but your example shows just what I need to build the message.

The method for concatenating is the piece of the puzzle I was missing.
Code: Select all
<cms:capture into='my_variable' 'global'><cms:show my_variable /> something else...
Something else on a new line.</cms:capture>

Thanks yet again for your unfailingly quick and effective help. :)
You are always welcome, @tim :)
4 posts Page 1 of 1