Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

IE/outlook: 'send page as e-mail'

the mail() function

Moderators: macek, egami, gesf

IE/outlook: 'send page as e-mail'

Postby simon44 » Wed Jun 29, 2005 6:58 am

I've a php script that accepts input and then displays info (after a mysql lookup).

If the user is browsing with IE and selects File->send->page as e-mail, the default
email client - outlook, pops up a window ready to send a copy of the page (in html).

The problem is that the message contains all the input and hidden variables that are used to
gather input.

I've tried this with various websites (eg this) and notice that hidden fields are also displayed.
Sometimes (eg phpmyadmin) outlook places the page as an attachment (why ?).

I know I can (andwill) send the email direct from my php script. Even so I still would like to
be able to control - or stop the user from seeing this. Maybe I have to first create a seperate html
file on my server that gets passed from IE to outlook.

any suggestions ?
simon44
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jun 29, 2005 6:15 am

Postby gesf » Thu Jun 30, 2005 4:16 pm

Try sending and receiving the page to see how it looks like after that!
Also check it's HTML to see if it was altered.

I think it just happens when we are previewing it.
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby simon44 » Wed Aug 17, 2005 3:58 am

Thanks for your reply gesf, I tried your suggestion but the mail arrives as displayed by outlook.
I think the problem is that the file is passed to outlook the form variables are unknown.
The following demonstates the problem (save as 'thisfile.php'). The script has 3 states:
input, display, print , if you try to email from ie (menu file/send/page as email) in any
state, the 'input state' part will always be displayed in the email body.


Code: Select all
<html>
<head>
<title>Send by email from internet explorer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php

$state = 'input';  // default state

if (isset($_POST['InputBtn']) && $_POST['InputBtn'] == "Input")
    $state = 'input';
if (isset($_POST['DisplayBtn']) && $_POST['DisplayBtn'] == "Display")
    $state = 'display';
if (isset($_POST['PrintBtn']) && $_POST['PrintBtn'] == "Print")
    $state = 'print';

?>
<form action="thisfile.php" method="post">
<?php
    switch ($state) {
    case 'input':
              echo "<p>Please enter some text:</p>"; ?>
           <input type="text" name="someinput" ><br><br>
           <input name="DisplayBtn" type="submit" value="Display">      
              <input name="PrintBtn" type="submit" value="Print"
               onclick="this.form.target='_preview';window.open('',this.form.target,'dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=400').focus();">         
<?php         break;
            
    case 'display': 
             echo "<p> You entered: ".$_POST['someinput']."</p>";
           echo "<p> Click 'Print' for a printable version </p>"; ?>
              <input name="someinput" type="hidden" value="<?php echo $_POST['someinput']; ?>">
           <input name="InputBtn" type="submit" value="Input">      
              <input name="PrintBtn" type="submit" value="Print"
               onclick="this.form.target='_preview';window.open('',this.form.target,'dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=400').focus();">         
<?php         break;
   
    case 'print':
              echo "<p> This is the printable version, displayed in a new window, with no buttons or input boxes</p>";
             echo "<p> You entered: ".$_POST['someinput']."</p><br>";
              echo "<p> Click <b>'File / Send / Page by E-mail..'</b> to send this page as email.</p>"; ?>
<?php         break;             
          
    } // end switch
?>
</form>


</body>
</html>




By the way, to create a new window from the onclick print button, the target is set to '_preview' in the above, does anyone know how '_preview' differs from '_blank' ?
simon44
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jun 29, 2005 6:15 am

Postby simon44 » Wed Aug 17, 2005 6:55 am

I think I've cracked it, when creating the printable/emailable version, switch on
output buffering, write the buffer to a temp file, then direct to the temp file using
header('Location: tempfile')...


Code: Select all
?php
$state = 'input';  // default state

if (isset($_POST['InputBtn']) && $_POST['InputBtn'] == "Input")
    $state = 'input';
if (isset($_POST['DisplayBtn']) && $_POST['DisplayBtn'] == "Display")
    $state = 'display';
if (isset($_POST['PrintBtn']) && $_POST['PrintBtn'] == "Print")  {
    ob_start();        // important to do this before html headers 
    $state = 'print';   
}
?>
<html>
<head>
<title>Send by email from internet explorer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="thisfile.php" method="post">
<?php
    switch ($state) {
    case 'input':
              echo "<p>Please enter some text:</p>"; ?>
           <input type="text" name="someinput" ><br><br>
           <input name="DisplayBtn" type="submit" value="Display">      
              <input name="PrintBtn" type="submit" value="Print"
               onclick="this.form.target='_preview';window.open('',this.form.target,'dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=400').focus();">         
<?php         break;
            
    case 'display': 
             echo "<p> You entered: ".$_POST['someinput']."</p>";
           echo "<p> Click 'Print' for a printable version </p>"; ?>
              <input name="someinput" type="hidden" value="<?php echo $_POST['someinput']; ?>">
           <input name="InputBtn" type="submit" value="Input">      
              <input name="PrintBtn" type="submit" value="Print"
               onclick="this.form.target='_preview';window.open('',this.form.target,'dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=400').focus();">         
<?php         break;
   
    case 'print':
              echo "<p> This is the printable version, displayed in a new window, with no buttons or input boxes</p>";
             echo "<p> You entered: ".$_POST['someinput']."</p><br>";
              echo "<p> Click <b>'File / Send / Page by E-mail..'</b> to send this page as email.</p>";
            $data = ob_get_contents();       
              $fp = fopen("printfile.htm", "w");
              fwrite($fp, $data);
              fclose($fp);
              ob_end_clean();
            header('Location: printfile.htm');
           break;                    
    } // end switch
?>
</form>
</body>
</html>


I still don't know why on some pages outlook adds as an attachment rather than in the
email body ? something in the html header perhaps ?

simon
simon44
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jun 29, 2005 6:15 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron