Closed Thread Icon

Topic awaiting preservation: can't print variables in HTML mail from PHP formmail (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11963" title="Pages that link to Topic awaiting preservation: can&amp;#039;t print variables in HTML mail from PHP formmail (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: can&#039;t print variables in HTML mail from PHP formmail <span class="small">(Page 1 of 1)</span>\

 
YoBoyE
Nervous Wreck (II) Inmate

From:
Insane since: Sep 2001

posted posted 12-22-2001 00:34

I have written a formmail in PHP, and I make the email I recieve an HTML mail, by specifying the appropriate headers in the formmail script. But a problem has arisen that I can't seem to figure a way out of. I can't figure out a way to print the fields that a user submits in the form to the email. I'm not sure why. Take a look at the code at http://66.34.243.107/contact.txt . When I recieve the email, the variables and stuff look like

$name

instead of the actual name sent in the form. Any help would be appreciated. Thanks in advance.

Eric Hesterman

[This message has been edited by YoBoyE (edited 12-22-2001).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-22-2001 00:46

not sure if that is the solution, but try to write:

$message = "...";
instead of
$message = '...';

inside type \" instead of all "

hth, but im afraid, not.



Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 12-22-2001 11:05

I don't think php recognizes the message as one string.

try

$message = <<<EOF
bla
bla
bla (your message nice and pretty here)
EOF;

good luck,

Tyberius Prime

YoBoyE
Nervous Wreck (II) Inmate

From:
Insane since: Sep 2001

posted posted 12-22-2001 15:52

Hmm, so far, nothing has worked. I tried GRUMBLE's suggestion a few times, but it's rather odd because with double quotes around the message, it didn't work, and with backslashes before the quotes, in my inbox it didn't even execute any of the html there. The EOF thing didn't work as well, but thanks a lot guys!!

Eric Hesterman

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-24-2001 09:57

Hello,

I made a solution for that, a bit tricky though...
here you go:

code:
// Read the mail file
$t = 'file_name_with_php_variables.txt';
$fp = fopen($t, 'rb');
$lines = fread($fp, filesize($t));
fclose($fp);
// add slashes to make valid PHP string
$t = '$t = "' . addcslashes($lines, '"') . '";';
// evaluate the code
eval($t);
//



your .txt file can contain something like:
hello $name,
and welcome!

in your php code prior to the snippet i gave, you can have this:
$name = 'Yoyo';
[mysnippet here]
now $t will have the same text found in your text file but w/ variables parsed!


Good luck!

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-26-2001 20:10

Did you get this fixed? Here's a function I wrote and use in a separately included file. It gathers all form fields and returns a string that contains all the key/value pairs (except for Submit) in a well-aligned format, and adds IP information. Check it:

code:
function gatherOutput() {
global $HTTP_POST_VARS, $HTTP_SERVER_VARS;
reset($HTTP_POST_VARS);
$maxLength = 0;
while (list($key,$value) = each($HTTP_POST_VARS)) {
if (strlen($key) > $maxLength) $maxLength = strlen($key);
}
for ($i=0; $i < $maxLength + 3; $i++) $emptyRow .= ' ';
reset($HTTP_POST_VARS);
while (list($key,$value) = each($HTTP_POST_VARS)) {
if ($value != '' && $key != 'Submit') {
$value = preg_replace ('/(\r\n)/',"\\1$emptyRow",$value);
if (is_array($value)) {
$firstRun = 1;
foreach ($value as $item) {
if ($firstRun) {
$pendingValue = $item;
$firstRun = 0;
} else {
$pendingValue .= "\r\n$emptyRow$item";
}
}
$value = $pendingValue;
}
$spacer = ' ';
for($i = 0; $i < ($maxLength - strlen($key)); $i++) $spacer .= ' ';
$output .= "$key$spacer: $value\n";
}
}
$output .= "\n\nForm Submitted by: {$HTTP_SERVER_VARS['REMOTE_ADDR']} aka {$HTTP_SERVER_VARS['REMOTE_HOST']}";
return $output;
}



One of my form processing scripts looks like this:

code:
$emailRecipient = "xxxxx@umn.edu, xxxxxxx@tcsu.umn.edu";
$emailSubject = "Alumni Group Event Registration Form";
$emailHeaders = "From: TCSU Alumni Group Webpage\nReply-to: $email";
$emailBody = gatherOutput();

mail($emailRecipient, $emailSubject, stripslashes($emailBody), $emailHeaders);



-jiblet

YoBoyE
Nervous Wreck (II) Inmate

From:
Insane since: Sep 2001

posted posted 12-30-2001 04:26

Jiblet, that script works to an extent. the only thing that ends up in my mailbox is the IP address and for example, 'Form Submitted by: 60.60.6.60 aka '. do I have to modify any parts of the script? thanks.


Eric Hesterman

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-30-2001 09:33

How do you call PHP script? If you're using GET method it won't work. You must use POST method instead...

<FORM ACTION="blah.php" METHOD="post"></FORM>


bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-30-2001 21:12

Also if you are only using this on a local box that is not named the IP is all you'll get.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

« BackwardsOnwards »

Show Forum Drop Down Menu