simple mail form error

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
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

simple mail form error

Post 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?
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: simple mail form error

Post 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 :)
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: simple mail form error

Post 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.
Post Reply