im trying to creat an email form with php here is wat I have and it isnt working

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jacob Sherman</title>
<link rel="stylesheet" href="content.css" type="text/css" />
</head>
<body>
<form action="" method="post" enctype="text/plain">
    <table border="0" cellspacing="0" cellpadding="4" width="90%">
        <tr>
            <td width="30%"><div align="right"><b>Name:</b></div></td>
            <td width="70%"><input type="text" name="name" size="20" /></td>
        </tr>

        <tr>
            <td><div align="right"><b>Email:</b></div></td>
            <td><input type="text" name="email" size="20" /></td>
        </tr>

        <tr>
            <td><div align="right"><b>Subject:</b></div></td>
            <td><input type="text" name="subject" /></td>
        </tr>

        <tr>
            <td><div align="right"><b>Comment:</b></div></td>
            <td><textarea name="comment" cols="30" rows="4"></textarea></td>
        </tr>

        <tr>
            <td>&nbsp;</td>
            <td>
                <input type="submit" name="submit" value="Submit" />
                <input type="reset" name="reset" value="Reset" />
            </td>
        </tr>
    </table>
</form>
<?php
    if($_POST['submit']){
        //retrieve all the information from the form
        $name = $_POST['name'];
        $email = $_POST['email'];
        $subject = $_POST['subject'];
        $comment = $_POST['comment'];
        
        //check to see if the data has been entered correctly
        if($name != "" && $email != "" && $subject != "" && $comment != ""){
            $email_pieces = explode("@", $email);
            $num_of_peices = sizeof($email_pieces);
            if($num_of_pieces != 2){
                echo "Please enter a correct email address and resubmit, thank you. </br>";
            }
            else{
                $filename = $subject . ".txt"; //should put together <subject>.txt
                
                $filelocation = "/localhost/" . $filename;//sets the filelocation
                
                $fp = fopen($filelocation, "w");//file location with the name of the file, which will be created if it isn't there
                //write all the data to a text file
                fwrite($fp, $name . "\n");
                fwrite($fp, $email . "\n");
                fwrite($fp, $subject . "\n");
                fwrite($fp, $comment);
                fclose($fp);//closes the file and saves
        
                echo "Your message has been successfully sent: " . $_POST['name'] . "!</br>";
            }
        }
        else{
            echo "Missing information, please enter all the information and re-submit, thanks </br>";
        }
    }    
?>
</body>
</html>

oh I found out the problem wasnt with the code but most likely with my php and apache set up. I just need to configure it right and it should work

This article has been dead for over six months. Start a new discussion instead.