Email the results of a database query

The mailer indeed is missing a repeater that should be handy in this case. I haven’t tested but perhaps you could try the following:

Create a repeater before the mailer, in the repeater you generate the html needed for each item and put it in a variable.

In you email you use the repeater output to join the html you generated there.

2 Likes

This is what I’ve done and it works well.

Thank you very much for your answers. I would try it but since already have started with some custom php I would have to take some drugs :slight_smile: in order to restart the email process.

What you suggest could work but in my case, I think it will get too complicated since the email itself has some conditions. For example, if the product was on sale then I have to display both prices, add some styling to the original price, and display the one with the sale. With normal php this is easier to control. Guess with your suggestion it would be more difficult to create.

Again thank you very much. If I wouldn’t have found a solution I would certainly try it.

Keeping it for the next time!

Thanks!

1 Like

I’m sure it’s a good idea to keep to your existing solution. However if at some point you want to use a more ‘Wappler’ approach, then I expect you may be able to incorporate the conditions you need in the MySQL part.

Eg I wanted to exclude rows where a particular field didn’t have a value (to avoid having a field label with no data), so one line of my trigger is:

IF (NEW.ISBN is null || NEW.ISBN = '','', CONCAT ( '<tr><td width="70"><span>ISBN:</span></td><td width="330">', NEW.ISBN, '</td></tr>')),

Creating HTML emails is a miserable task however you do it.

Hopefully by the time you need this feature again, Wappler’s mailer extension will be more capable. It is one of the bigger omissions in Wappler at the moment.

2 Likes

So true. And the worst is that clients think is just a matter of minutes to create something like that. I am, so often, thinking what other developers (that are not using Wappler or something similar (if it exists)) really do. I mean you create something that is complicated, make it work with minimal clicks and they still don't understand how much work there is behind it. If I had to create by handcoding what I create with Wappler I would be so desperate.

3 Likes

Hi I have used another approach to this exact situation.

Create a dynamic page on the web server (PHP, ASP.NET OR ASP) connected to your database and formatted to display the results you need based on QueryString Values sent to the page. Then use “MHTML BODY” in the email script with the body content retrieving the page described plus dynamic QueryString Values to run the page. The recipient gets a beautiful HTML email formatted exactly as you need. Just be sure to include any email page CSS in the head of the included file rather than from the website to make sure it gets styled correctly. Typical code as final line in the email sending script in this case using CDO…

…blah, blah set up email…then final line…
objMessage.CreateMHTMLBody “https://yoursite.co.uk/orders/orderlist.asp?OrderID=” & rsMyRecordset(“OrderID”)

Wouldn’t this only work if you’re using some form of ASP and a Windows server?

yes, that looks very ASP specific but the principle is the same in PHP, just different send code

Yes my example is ASP but would work in any language with modified code. the principle is that the dynamic email page content can be formatted as wished, repeat regions etc. It just needs the query string values sent from the email script to retrieve the page as the email body. In PHP typically the MHTML would be replaced with something like … $body = "http://site.co.uk/orders.php?OrderID =

…and in ASP.NET

message.IsBodyHtml = true;
message.Body = “http://site.co.uk/orders.aspx?OrderID=XXXXXX”;

Hi @diggybob
I have an asp page with a table populated by a ServerConnect repeat
http://myserver/table/emailrow.asp?value=1

In my page that submits the Email using the SendMail action where in Wappler do I add objMessage.CreateMHTMLBody “http://myserver/table/emailrow.asp?value=1”

Thanks

Personally i prefer to build the HTML body in the server action rather than at app connect side

I simply define a variable within the server action and use “set Value” to add HTML to the variable then simply send it at the end with send mail, no need for client interaction, no custom ASP code, 100% Wappler

Something like this

9 Likes

Thanks @Hyperbytes, I’ll give it a try.
It would be great if repeat regions could easily be added to Wappler email bodies at some point though.

2 Likes

Yes it is a bit of a pain to build these manually using repeats

For info, the above mentioned one produced this, a table of properties with images (still being tweaked, more info to add)

Really clever what you did!
This actually demonstrates that Wappler is actually a programming software. It will just take a little more of time for the mass to understand that Wappler is the only software that actually programs by mostly clicking in order to save time and effort and to be able to focus on more strategic decisions.

Congrats @Hyperbytes, personally I find this as one of the most interesting posts that shows how incredible Wappler actually is

4 Likes

May I submit a request for a tutorial on this? Would that be possible @Hyperbytes?

1 Like

Yes but it may be a few weeks until i get my current project finished. Promised myself a week Wappler play break before starting the next big one.

2 Likes

Hi @revjrblack, I thinking to request the same.
@Hyperbytes opens a big and interesting window

3 Likes

We would rather exercise the virtue of patience, and never rush the master. Ha!

2 Likes

Did anything get introduced into Wappler over the past 12 months to make it easier to send repeat region data html template in an email? e.g the contents of an abandoned shopping cart