mailing $_POST variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

mailing $_POST variables

Post by kendall »

Hi,

Im having a bit of a problem mailing $_POST variables using the mail() function

i have the following code required from a file which mails $_POST variables after they are validated and entered into a database

while(list($key,$value)=each($_POST)){
$message .= $key.":".$value."\n";
}
$subject = "POST information from USER: ".$USER;
mail('kendall@apex-solutions.com',$subject,$message);

I get the email but no message

just running tru the code description i am trying to concatenate the key value pairs in to message variable before i send it off.

Am i using this part correctly as i can't seem to pin point a problem

Kendall
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Hi Kendall,

Have you tried to place a counter in the while loop? It might tell you how many times it went through. If it returns 0 then you might want to take a look at you $_POST variable in case it's emptied earlier before the while loop...

Is the result verified in the same file without reloading?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried putting:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
in the script that receives the POST variables from the form to make sure that they're getting passed ok?

Mac
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

mailing $_POST variables

Post by kendall »

Hey,

ok heres what i did.

instead of the while...list loop i did a foreach and it was able to produce the 'elements' in the post array.

so if it was able to do a foreach without error. why is it not displaying a 'key : value '. does it have to do with an incorrect order of the array or something?

im a bit confused now as to what to look for as a possible error

Kendall
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

mailing $_POST variables

Post by kendall »

Hey guys,

i have a question but first heres the scenario

on posting a form

the script calls a function from a required file to validate

i then do a while list loop to check the $POSTs to replace empty values with 'NULL'

it is then placed in a database

and then after i do the while list loop to generate a "key : value" string to be sent in as a message mail()

Now the part where i replace the empty values wit 'NULL' does this have anything to do with it??

my theory is maybe when i while list i have a if empty replace the value in the post array wit null. i think therefore i am redefinint he variable and is not a POSTed variable anymore.

but then my question is isnt it a global variable and even if it is the same $_POST so while isnt it recognising it at the end.

now as a test i inserted the code in question and placed it at the begining of the script and it worked. so why isnt it working at the end??

any takers?

?Kendall
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

mailing $_POST variables

Post by kendall »

Hey guys,

am this is weird but

it seems to work when i just list the values using the foreach loop

but doesnt list anything when i use a while(list....each($_POST))

what gives here
?
Post Reply