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 = "[email protected]";

           

            $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
https://forums.phpfreaks.com/topic/220401-php-contact-form-not-working/
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

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.