Hello,
I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):
http://www.phptr.com/essential/php/code/chapter6.zip
Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.
Get to the point...
Ok, ok...
To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.
The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.
I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.
If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.
What gives ??
See my code below...
Paul Gosselin
St-Augustin.
Note from Screwtape, the demon:
"If we neglect our duty, men will be not only contented but transported by the mixed novelty and familiarity of snowdrops this January, sunrises this morning, plum pudding this Christmas. ( ) Only by our incessant efforts is the demand for infinite, or unrhythmical, change kept up."
- The Screwtape Letters (p. 127-128)
check le site:
http://www.samizdat.qc.ca
HTML page (this is the form with transmits the URL)
<form name="FormName" action="../../modules/env_art.php" method="post">
<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article à un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
</form>
PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Envoyez l'article11</title>
</head>
<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">
<h2>Envoyez l'article</h2>
<p>
<form action="env_art.php" method="POST">
</p><br><br>
<table border="0" cellpadding="0" cellspacing="5" width="400">
<tr>
<td width="300" align="right">Couriel de votre destinataire:</td>
<td width="100"><input type="text" name="to" size="24"></td>
</tr>
<tr>
<td width="300" align="right">Votre couriel:</td>
<td width="100"><input type="text" name="from" size="24"></td>
</tr>
<tr>
<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Envoyez!">
</form>
</p>
<?
//this is just to see if the variable got thru ok
print "" . $article . "";
if(isset($submit)):
//next 3 lines may be useless...
$article = str_replace("%2F","/",$article);
$article = str_replace("%3A",":",$article);
$article = trim( $article );
($file = fopen( $article, "r" )) or die ("Can't open file");
$data = fread( $file, 200000 );
fclose($file);
//$stripped_data = strip_tags($data);
$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
$subject = "Un article pour toi de la part d'un(e) ami(e)";
mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
print"<h2>The article has been sent !</h2>"
?>
<p>
<?
endif;
?>
</body>