Question: Send a GRID by email, is it possible?

How to send the output of a GRID by email?
Is it possible?

We know you can send the output of a grid to a PDF, Word, XLS.
but it is possible send to mail in HTML format?

thanks.

I have the same question… is it possible to send a HTML print by email? I want to avoid coding a table in HTML my self… I tried to send a Grid (HTML print) using <iframe src… but it wont appear in the email, just a blank space.
Any idea?

Hi SuperGabo & Misael,
You can send the output of a grid generated by scriptcase. You need to put this PHP function ob_start(); onScriptinit and ob_end_clean(); onFooter.

[SIZE=4]Example to: Store HTML into a variable[/SIZE]
[SIZE=3]onScriptInit[/SIZE]


 ob_start(); // buffer start

All the output HTML code between ‘ob_start()’ to ‘ob_end_clean()’ will be stored in a variable
[SIZE=3]onFooter[/SIZE]


$html=ob_get_contents();  // store buffer to $html
ob_end_clean(); // end buffer

Now you can send your email using the $html variable.

Thanks, Hiram.

I’m using a control application that gets info from a database and sends an email using that information… so in order to make this work I would need to run the grid first and make the $html global, right?

Another question, where exactly is this?: “at the start of the output and this at the end”

Thanks again,
Misael.

The proposed functions come from php. See: http://php.net/manual/en/function.ob-start.php

You cannot use the grid to generate the output afaik. But you can reuse the sql statement and create your own output. This output (in html format) is then used for emailing. You have to generate the html yourself the way you need.

-open database
-set cursor on select
-start output table
-for each row

  • create a row <tr>
    — for each field
    — create field <td>
    -close table

send email

Hi Misael lets clarify the example:

If you want to get the HTML code of a grid generated by scriptcase and store into a PHP variable then
write this line onScriptinit of your GRID APP:

ob_start();

then onFooter of GRID APP:

$html=ob_get_contents(); 
ob_end_clean(); 

This is tested using a grid application (and its working), if you run that code all the grid will be inside the $html variable if you want to see the grid HTML code just echo the $html variable.
add this line onFooter of GRID APP to see the grid:

echo $html;

So if you want to send an email you will need the $html variable that contains all the HTML code of the grid.
For example using the mail function of PHP the code will be like this

add this code onFooter of GRID APP to send an email:



$to = "hirambq@scriptcase.net";     
$from = "misael@scriptcase.net";     
$subject = "Hello! This is my grid"; 
$headers  = "From: $from
Content-type: text/html
"; 

mail($to, $subject, $html, $headers); 
echo "E-mail has been sent....!"; 


Note: obviously if you write your own function to generate the HTML grid will be a more clean html code.

Thanks for clearifying. Never used the ob_ functions. $html=ob_get_contents(); is a great way to get the html data from the buffer. But if you grid is larger and over more pages, how do you solve this? Afaik you only get the page into your html? That’s why I alway create a manual php script to fill a string. But intercepting echo is a better way of doing it. Never to old to learn :wink:

Thanks for the explanation!, I’ll try it today.

I tried to use this to print a form, but it does not seem to work. Have you figured out how to do this? I can print the screen by creating a button / javascript and apply window.print(); but it will print my buttons too.