Click to See Complete Forum and Search --> : post


agent_x91
08-05-2005, 09:46 PM
I'm a little confused about PHP's $_POST. I thought I had a rough idea of how to use it but apparently not, because it ended up blank in my script after using a form action to redirect there. Can someone help? I've tried using a form in mailer.php to send the appropriate values to mail.php, which then sends it. However, $_POST items are appearing empty, so it's not sending a subject, messagecontents, from address, etc.

The source of the two files are below.


mailer.php:


<html>
<head>
</head>
<body>

<form action="mail.php" method="post">

<center>
<table>

<tr>
<td><center><b>Subject</b></center></td>
<td><center><input name="subject" size=30></center></td>
</tr>

<tr rowspan=5>
<td><center><b>Message</b></center></td>
<td><center><textarea name="contents" rows=5 cols=30></textarea></center></td>
</tr>

<tr>
<td><center><b>From</b></center></td>
<td><center><input name="nfrom" size=30></center></td>
</tr>

</table>


</center>

<input type="submit" name="submit" value="Submit">

</form>

</body>
</html>


mail.php:


<?php
$addrto="agent_of_oblivion_91@hotmail.com";
$namefrom=$_POST['nfrom'];
$subject=$_POST['subject'];
$contents=$_POST['contents'];

echo $namefrom;

$addcontents="A message has been sent from the mail script at http://hellfusion.freewebsitehost.net\n\n";


mail($addrto,$subject,$addcontents.$contents,"From:$namefrom");

?>



Any help would be appreciated.

Sheldon
08-05-2005, 09:58 PM
try this for your mail.php


<?php

$recipient = "you@domain.com";
$subject = "{$_POST['subject']}";
$sender = "{$_POST['nfrom']}";
$headers = "From: $sender\r\nReply-to: $sender";




$comments = $_POST['comments'];
$email = $_POST['nfrom'];

$input = "A message has been sent from the mail script at http://hellfusion.freewebsitehost.net\n\n$email said $comments\n\n";
if(mail($recipient, $subject, $input, $headers)){
header("location: thanks.html");
}else{
echo 'There was an error sending mail';
}


?>


Sheldon

aznchong91
08-05-2005, 10:56 PM
The post variable itself should be working. I don't really know what's wrong. It could just be your mailing, not the variables, that has a problem.

agent_x91
08-06-2005, 05:26 AM
It's not my mailing. It works fine when I just use strings instead of variables, and when I try to echo $_POST variables, they appear blank as well.

aznchong91
08-06-2005, 05:54 AM
THEN...i have no idea :confused: :D
It could be just a syntax error, but i don't see it.