This topic is locked

Email a list page using a button

6/26/2006 6:57:59 PM
PHPRunner General questions
D
Dale author

OH how I wish I knew all this stuff.
I have been trying to Email a list page using a button and script and I have no success.

I had asked this question a while ago and a forum member was gracious enough to show me some php script that would capture the page and email it.
<?php

ob_start(); // start capture of html to buffer

?>
....Your Invoice page
<?php

$page_content = ob_get_contents(); // place buffer contents in variable

ob_end_clean(); // stop buffer capture
// To send HTML mail, the Content-type header must be set

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: from_whoever <fromwhoever@domain.com.com>' . "\r\n"; //this could be done here or in the mail function itself
echo $page_content; //send page to user for viewing
mail("to_whoever@domain.com","Subject line",$page_content,$headers); // mail as html mailbody

?>
The code works perfectly, except it immediately emails the page.
I want to email the page by adding a button on the list page Email Statement.
Can anyone help me out with a script snippet to email the page after it is displayed and with a button.

Once the Email Statement is emailed I would like a message popup IF the email has been sent, or an error is something went wrong.
Any help will be greatly appreciated.

Alexey admin 6/27/2006

Dale,
I recommend you to create a separate email.php page that will send a message and accept its text as POST parameter.

Here are the sample contents of this file:

<?php

mail("to_whoever@domain.com","Subject line",$_POST["page_content"],$_POST["headers"]); // mail as html mailbody

?>


And here is the code for Send button on the main page:

...

?>

<form name="mailform" method="post" action="mail.php">

<input type=hidden name=page_content value="<?php echo htmlspecialchars($page_contents);?>">

<input type=hidden name=headers value="<?php echo htmlspecialchars($headers);?>">

<input type=submit value="Send">

</form>

<?php

...



Make sure this code doesn't get into another form.

D
Dale author 6/27/2006

Dale,

I recommend you to create a separate email.php page that will send a message and accept its text as POST parameter.

Here are the sample contents of this file:
And here is the code for Send button on the main page:
Make sure this code doesn't get into another form.


Thankyou for your response. I will try it out asap.

It's great to have such good support.