Hi,

So I'm working on a shirt printing quoter for a client. Basically you fill out a few fields and it tells you how much it would cost to print your design on 24+ shirts. After you see your total, you can place your order by filling in contact info and submitting the order. This is supposed to send an email to the company with your order details, as well as to you as a sort of receipt.

I would like to make my life a lot simpler by just storing the source of a page I already generated, as a variable, and then using that as the message body. Does anyone know if there is a way to do this? The page is dynamically generated, so it's not just a static page I can link to.

Thanks

You could use ob_start() , include the file that creates the page (taking care to add any necessary GET variables to the include path as you would with a URL), and then store the contents of ob_get_contents() in a variable. Demo below:

index.php

//Start output buffering
ob_start();
//Get the contents of the dynamic page
require('dynamic.php?a=10');
//Get the contents of the page through the OB
$contents = ob_get_contents();

//To demonstrate it works
echo '$contents = ';
var_dump($contents);

dynamic.php

//Sample dynamic content
echo 'This is dynamic. A = '.$_GET['a'];

If you need to send POST variables to the dynamic page you could use cURL instead. A demo of this is below.

index.php

//Init curl and set some required  options
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTANSFER, true);
//Set the URL (w/ get variables) and any post fields
curl_setopt($c, CURLOPT_URL, 'dynamic.php?a=10');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'b=5');
//Get page contents and close cURL
$contents = curl_exec($c);
curl_close($c);

//To demonstrate it works
echo '$contents = ';
var_dump($contents);

dynamic.php

//Sample dynamic content
echo 'This is dynamic. A = '.$_GET['a'].', B = '.$_POST['b'];

Hi,

So I'm working on a shirt printing quoter for a client. Basically you fill out a few fields and it tells you how much it would cost to print your design on 24+ shirts. After you see your total, you can place your order by filling in contact info and submitting the order. This is supposed to send an email to the company with your order details, as well as to you as a sort of receipt.

I would like to make my life a lot simpler by just storing the source of a page I already generated, as a variable, and then using that as the message body. Does anyone know if there is a way to do this? The page is dynamically generated, so it's not just a static page I can link to.

Thanks

hi there! Ϋ

would you mind displaying a part of your code that has relation with that?
that's to solve the problem faster.

:) thanks.

hi there! Ϋ

would you mind displaying a part of your code that has relation with that?
that's to solve the problem faster.

:) thanks.

If you absolutely want it from baudday, you can ask for some code, but I found that baudday's description of what he/she was looking for was sufficient to come to a solution.

If you absolutely want it from baudday, you can ask for some code, but I found that baudday's description of what he/she was looking for was sufficient to come to a solution.

:) hey there PMC.

i do also have an idea about on what baudday's asking for.
programmers have different ways in solving the same problem, right?

mine's to adjudicate first if possible, the summary of a whole program code,
and after doing so that's when I'll start giving it a shot. Ϋ

it's also my way on knowing how good the person is in terms of his or her coding.
and just so you know i guess you're one of the best already. Ϋ

:icon_wink: mabuhay ka PMC!

Okay that first example actually helped a lot. I did the following. I use codeigniter, so a code sample would've been irrelevant in this case.

ob_start();

//Content I want in the email gets loaded normally here...

$page=ob_get_contents(); //get the page
	 
$message = $page;
$this->session->set_userdata(array('message' => $message));

ob_end_flush();

This actually worked with POST variables too! So this is just great! I can send an exact duplicate of the order summary as a receipt via email.

Thanks a lot guys!

:) hey there PMC.

i do also have an idea about on what baudday's asking for.
programmers have different ways in solving the same problem, right?

mine's to adjudicate first if possible, the summary of a whole program code,
and after doing so that's when I'll start giving it a shot. Ϋ

it's also my way on knowing how good the person is in terms of his or her coding.
and just so you know i guess you're one of the best already. Ϋ

:icon_wink: mabuhay ka PMC!

You have a valid point. Sometimes it is better to post code (as a rule, it's a good idea to post some for reference) and other times its not. Though, as the asker, its nicer if answers can be tailored to their exact needs. Salamat ﻼim!

baudday: If this thread has been solved, please make sure to mark it as solved so other users know that this thread does not need further clarification. Thanks! :D

You have a valid point. Sometimes it is better to post code (as a rule, it's a good idea to post some for reference) and other times its not. Though, as the asker, its nicer if answers can be tailored to their exact needs. Salamat ﻼim!

baudday: If this thread has been solved, please make sure to mark it as solved so other users know that this thread does not need further clarification. Thanks! :D

this just proves that i still have a lot to learn! :$
i haven't used any of the functions here.
really nice to know all this.

thanks PMC. Ϋ

this just proves that i still have a lot to learn! :$
i haven't used any of the functions here.
really nice to know all this.

thanks PMC. Ϋ

You're welcome! :D

As you learn more about PHP, you'll see a lot of these useful features like cURL. As it says in my signature, be sure to take some time to look over some of the listed extensions on the PHP.net documentation. You'll discover some other great extensions such as the GD image library. Best of luck with your future PHP scripts!
-PMC

You're welcome! :D

As you learn more about PHP, you'll see a lot of these useful features like cURL. As it says in my signature, be sure to take some time to look over some of the listed extensions on the PHP.net documentation. You'll discover some other great extensions such as the GD image library. Best of luck with your future PHP scripts!
-PMC

thanks PHP man. Ϋ
anyway php.net would always be my last resort regarding with php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.