Jump to content

PHP Contact Form Not Working


defektdesigns

Recommended Posts

Hi I am brand new to PHP Freaks and really hope someone can help me out with my php problem. I have a contact form that I am using and all the php and form info is in one file. The contact form worked before but it wasn't correct because one of the names was wrong on the form.

 

Here is the php I have put just below the opening body tag:

 

<?php

      $name = $_POST["name"];

        $email = $_POST["email"];

        $subject = $_POST["subject"];

        $comment = $_POST["comment"];

        $submit = $_POST["submit"];

       

        if(isset($submit)){

            $sendTo = "myemail@mydomain.com";

           

            $message = "<h3>To You:</h3>

                $comment<br />

                <br />

                From: $name ($email)";

               

            $headers = "From: $name <$email> \r\n";

            $headers .= "X-Mailer:PHP/\r\n";

            $headers .= "MIME-Version:1.0\r\n";

            $headers .= "Content-type:text/html; charset=iso-8859-1\r\n";

           

            $sent = mail($sendTo, $subject, $message, $headers);

        }

?>

 

and here is the form:

 

 

<form action="" method="post">

            <table>

                <tr>

                    <td>Name: </td>

                    <td><input type="text" name="name"  class="field"/></td>

                </tr>

               

                <tr>

                    <td>Email: </td>

                    <td><input type="text" name="email" class="field" /></td>

                </tr>

               

                <tr>

                    <td>Subject: </td>

                    <td><input type="text" name="subject"  class="field"/></td>

                </tr>

               

                <tr>

                    <td>Comment: </td>

                    <td><textarea name="comment" cols="30" rows="8" > </textarea></td>

                </tr>

               

                <tr>

                    <td><input type="submit" name="submit"  value="Send" /></td>

                </tr>

            </table>

        </form>

               

 

  <?php

if ($sent){

              echo "Thank you for your message!";

                }

?>

 

now when I had it working I had accidentally had the subject name set to "email" but when I simply change it to "subject" as it should be it won't work anymore. I would love to just let it work the wrong way but this won't work because when I receive the email it displays the subject instead of the persons email and I need to see the email to get back to them.

 

I really hope someone can help me with this!

 

Thanks,

Curtis

 

Link to comment
Share on other sites

well have you tried to instead of

<form action="" method="post">

 

add

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

  ???

 

your page should do the post action somewhere isnt it?if te process happens on the same page (it means both php and html codes are in the same page) add the page name to your action

 

i hope it helps

Link to comment
Share on other sites

I'll try my best to explain it.

 

It will work if i simply change <input type="text" name="subject"  class="field"/> to <input type="text" name="email"  class="field"/>

 

but for some reason if I make it <input type="text" name="subject"  class="field"/> it will not work.

 

Yes the php and the html form are in the same file called contact.php

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.