Page 1 of 1
Including file in mail
Posted: Sun Oct 06, 2002 9:43 am
by Zeceer
I got a document before the actual mail script. This document have two hidden variables.
<input name="username" type="hidden" value="<?=$username?>">
<input name="password" type="hidden" value="<?=$password?>">
These variables are sent with the document to this file:
<?php
$to = "
zeceer@hotmail.com";
$subject = "Order";
$headers = "
zeceer@hotmail.com";
$body ="
Navn: ".$_POST['navn']."
Post adresse: ".$_POST['postadresse']."
Postnummer: ".$_POST['postnummer']."
Sted: ".$_POST['sted']."
Telefon: ".$_POST['telefon']."
E-mail: ".$_POST['email'];
mail($to,$subject,$body,"From: $headers");
header( "Location: index.php" );
?>
The two variables that are passed is set together so they match a file.
include(users/'.$_POST[username].$_POST[password].'.php');
What i need i something that includes this file in the $body variable of the mail script. So that the body of the mail is that file. Or whats inside the file is printet in the mail. If you know what mean

.
A stupid example just to show what I mean

:
<?php
$to = "
zeceer@hotmail.com";
$subject = "Order";
$headers = "
zeceer@hotmail.com";
$body ="
Navn: ".$_POST['navn']."
Post adresse: ".$_POST['postadresse']."
Postnummer: ".$_POST['postnummer']."
Sted: ".$_POST['sted']."
Telefon: ".$_POST['telefon']."
E-mail: ".$_POST['email']
include(users/'.$_POST[username].$_POST[password].'.php');
;
mail($to,$subject,$body,"From: $headers");
header( "Location: index.php" );
?>
The thing is that this file contains information about the user that I need
Posted: Sun Oct 06, 2002 10:49 am
by Takuma
Why not use fopen and fread?
Code: Select all
<?php
$fp = fopen("users/{$_POSTїusername]}.{$_POSTїpassword]}.php");
$content = fread($fp,filesize("users/{$_POSTїusername]}.{$_POSTїpassword]}.php"));
fclose($fp);
$body .= $fp;
?>
Posted: Mon Oct 07, 2002 10:25 am
by Zeceer
Tried your example. Didn't make it work, but it leaded me in the right direction

.
I made this:
<?php
$to = "
zeceer@hotmail.com";
$subject = "Order";
$headers = "
zeceer@hotmail.com";
$fp = fopen('brukere/'.$_POST['brukernavn'].$_POST['passord'].'.php', "r");
$body = fpassthru( $fp );
mail($to,$subject,$body,"From: $headers");
?>
It worked 50%

. It prints the file to the browser and everyhing looks fine untill I get the mail. The mail only says "1622" for some reason. What I need is something that put's the text inside of the file in the body of the mail

Posted: Tue Oct 08, 2002 9:51 am
by Zeceer
Anyone?
Posted: Tue Oct 08, 2002 9:59 am
by nielsene
fpassthru returnes the number of characters read, so thats why your email's body was 1622. fpassthru displays the file to screen as a side effect which is why it looked good on the browser.
Modifiying Takuma's version
Code: Select all
<?php
$fp = fopen("users/{$_POSTїusername]}.{$_POSTїpassword]}.php");
$content = fread($fp,filesize("users/{$_POSTїusername]}.{$_POSTїpassword]}.php"));
fclose($fp);
$body .= $content; // not $fp!
?>
This should work. If it doesn't tell us why and we can take it from there.
Posted: Wed Oct 09, 2002 6:18 am
by Zeceer
Why is this error popping up?
Parse error: parse error, unexpected T_VARIABLE in D:\inc shop\tilkassen3.php on line 4
Heres the script:
<?php
$fp = fopen("brukere/".$_POST['brukernavn']$_POST['passord'].".php");
$content = fread($fp,filesize("brukere/".$_POST['brukernavn']$_POST['passord'].".php"));
fclose($fp);
$body = "$content";
print("$body");
?>
[/quote]
Posted: Wed Oct 09, 2002 7:21 am
by twigletmac
You need to add a period (.) between your variables in order to concenate them:
Code: Select all
$_POSTї'brukernavn'].$_POSTї'passord']
instead of
Code: Select all
$_POSTї'brukernavn']$_POSTї'passord']
Mac
Posted: Wed Oct 09, 2002 7:40 am
by Zeceer
I had it that way before, but then I get this pretty lady

:
Warning: Wrong parameter count for fopen() in D:\inc shop\tilkassen3.php on line 4
Warning: fread(): supplied argument is not a valid File-Handle resource in D:\inc shop\tilkassen3.php on line 5
Warning: fclose(): supplied argument is not a valid File-Handle resource in D:\inc shop\tilkassen3.php on line 6
Posted: Wed Oct 09, 2002 7:43 am
by twigletmac
fopen() requires two parameters to be passed to it, the filename and the mode which should be used to open the file. More info about the choice of mode is available here:
http://www.php.net/manual/en/function.fopen.php
Mac
Posted: Wed Oct 09, 2002 7:46 am
by Zeceer
Stupid ME! Done that mistake before

. Thanx!
THIS HAS NOTHING TO DO WITH THE POST ABOVE
Posted: Wed Oct 09, 2002 8:53 am
by Zeceer
When I send this to a hotmail account it works great. It displays the text as HTML. But by sending it to some other account it only display the HTML codes as basic text. What I want is to display the mail as HTML. In other mail programs than Hotmail. Is there i code I must include so the mail client displays it as HTML??
<br>
Navn: gg
<br>
Post adresse: dg
<br>
Postnummer: dgq
<br>
Sted: fgdg
<br>
Telefon: gdfgws
<br>
E-mail: grg
<html>
<body>
<table width="650" border="0" cellspacing="0" align="center"
bgcolor="#ffffff"><tr><td width="200" valign="left"><font color="#000000" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Whey Tech 3000g</font></td><td
width="200" align="right"><font color="#000000" size="1" face="Verdana, Arial,
Helvetica, sans-serif"><strong>1</strong></font></td><td width="200"
align="right"><font color="#000000" size="1" face="Verdana, Arial, Helvetica,
sans-serif"><strong>729,-</strong></font></td></tr></table><br><?php $pris = $pris +
"729"; ?>
<table width="650" border="0" cellspacing="0" align="center"
bgcolor="#ffffff"><tr><td width="200" valign="left"><font color="#000000" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Whey Tech 1500g</font></td><td
width="200" align="right"><font color="#000000" size="1" face="Verdana, Arial,
Helvetica, sans-serif"><strong>1</strong></font></td><td width="200"
align="right"><font color="#000000" size="1" face="Verdana, Arial, Helvetica,
sans-serif"><strong>429,-</strong></font></td></tr></table><br><?php $pris = $pris +
"429"; ?>
<table width="650" border="0" cellspacing="0" align="center"
bgcolor="#ffffff"><tr><td width="200" valign="left"><font color="#000000" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Whey Tech 750g</font></td><td
width="200" align="right"><font color="#000000" size="1" face="Verdana, Arial,
Helvetica, sans-serif"><strong>1</strong></font></td><td width="200"
align="right"><font color="#000000" size="1" face="Verdana, Arial, Helvetica,
sans-serif"><strong>279,-</strong></font></td></tr></table><br><?php $pris = $pris +
"279"; ?>
</body>
</html>
Posted: Wed Oct 09, 2002 9:00 am
by twigletmac
Have you put in all the headers (content type and MIME) needed for HTML mail as given on this page
http://www.php.net/manual/en/function.mail.php?
(Check out Example 4: Sending Complex Email)
Mac
Posted: Wed Oct 09, 2002 1:16 pm
by Zeceer
Thanx, that worked fine. The only problem is that i can't set who the mail is from. I've tried some solutions but didn't get it.
Heres my mail() line.
mail($to,$subject,$body,"Content-type: text/html; charset=iso-8859-1\r\n");
Posted: Thu Oct 10, 2002 1:55 am
by twigletmac
You can add a from line in your headers (check the docs on the mail function for what it should look like) but that may not work depending on whether you are using windows or *nix but the manual page will explain more.
Mac
Posted: Thu Oct 10, 2002 7:37 am
by Zeceer
I tried that, but didn't get it. Gonna read the whole manual and then try.