Page 1 of 1

simple mail form error

Posted: Thu Dec 24, 2009 1:17 am
by indian98476

Code: Select all

<? //initilize PHP
if($_POST['submit']) 
{
$email=$_POST['email'];
$sub=$_POST['subject'];
$to="someone@example.com";
$msg=$_POST['comments'];
mail($to,$sub,$msg,"From:$email");
echo "a mail has been sent from ".$email." to ".$to.".";
}
else
{
?>
 
    <form method="post" action="">
 
    <? echo "<br />"; ?>
    E-Mail: <INPUT TYPE="TEXT" NAME="email" size=60> 
    <? echo "<br />"; ?>
    Subject: <INPUT TYPE="TEXT" NAME="subject" size=60>
    <? echo "<br />"; ?>
    Comments:   <? echo "<br />"; ?><TEXTAREA NAME="comments" ROWS=3 COLS=30></TEXTAREA> //comments
    <? echo "<br />"; ?>
    <input type="submit" name="submit" value="submit">
    </form>
 
<? }?>
the message gets displayed that email has been sent from x to y but when y checks his/her mailbox y finds no mail. what could be wrong?

Re: simple mail form error

Posted: Thu Dec 24, 2009 6:03 am
by oscardog
Try setting the headers parameter in the mail() function before you use it, so set a variable $from and set like:

$from = "From:" . $email;

then mail($to, $sub. $msg, $from);

Might not have any affect, but worth a shot :)

Re: simple mail form error

Posted: Thu Dec 24, 2009 8:28 am
by omniuni
This may be a "dumb" question, but is the server correctly configured? If it is not, it may be mailing to a null interface instead of dispatching via SMTP. Write a one-liner script to send yourself a test mail, and make sure it's working.