Can't get php contact form to work

I have a webpage that has two contact forms and the second one is working fine but I can't seem to get the first one to work. I am fairly new to php. Thanks in advance for the help. Here's the html:

        <h3>Message Us</h3>
        <form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
            <input type="hidden" name="scrollx" id="scrollx" value="0" />
            <input type="hidden" name="scrolly" id="scrolly" value="0" />
            <div id="msgbox1">
                <label for="name2">Name:</label>
                <input type="text" id="name2" name="name2" placeholder=" Required" />

                <label for="email2">Email:</label>
                <input type="text" id="email2" name="email2" placeholder=" Required" />

            <label for="phone">Phone:</label>
            <input type="text" id="phone" name="phone" placeholder="" />

                <label for= "topic">Topic:</label>
                <select id="topic" name="topic">
                    <option value="general">General</option>
                    <option value="stud">Property Price Enquiry</option>
                    <option value="sale">Bull Sale Enquiry</option> 
                </select>
            </div><!--- msg box 1 -->
            <div id="msgbox2">    
                <textarea id="message" name="message" rows="7" colums="25" placeholder="Your Message?"></textarea>
                <p id="feedback2"><?php echo $feedback2; ?></p>
                <input type="submit" value="Send Message" />
            </div><!--- msg box 2 -->
        </form><!--- end form -->
    </div><!--- end message box -->

And here's the php:

<?php 

$to2 = '418@hotmail.com'; $subject2 = 'MPG Website Enquiry';

$name2 = $_POST ['name2']; $email2 = $_POST ['email2']; $phone = $_POST ['phone']; $topic = $_POST ['topic']; $message = $_POST ['message'];

$body2 = <<<EMAIL

This is a message from $name2 Topic: $topic 

Message: $message

From: $name2 Email: $email2 Phone: $phone

EMAIL;

$header2 = ' From: $email2';

if($_POST['submit']=='Send Message'){
    if($name2 == '' || $email2 == '' || $message == ''){
        $feedback2 = '*Please fill out all the fields';  
    }else {
        mail($to2, $subject2, $body2, $header2);
        $feedback2 = 'Thanks for the message. <br /> We will contact you soon!';
    } } ?>

For the saveScrollPositions I use the following php and script:

<?php

$scrollx = 0;

$scrolly = 0;

if(!empty($_REQUEST['scrollx'])) {

$scrollx = $_REQUEST['scrollx'];

}

if(!empty($_REQUEST['scrolly'])) {

$scrolly = $_REQUEST['scrolly'];

}

?>

<script type="text/javascript">

window.scrollTo(<?php echo "$scrollx" ?>, <?php echo "$scrolly" ?>);

</script>

Answers


You have a mistake in your HTML part i.e.

<input type="submit" value="Send Message" />

add attribute name also in this input type like this-

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

one thing more to correct in your php script is write-

$header2 = "From: ".$email2;  instead of  $header2 = ' From: $email2';

now try it.


What do you return in "saveScrollPositions" function? if you return false the form submit wont fire.


Need Your Help

Function to create a tree of properties?

c# class reflection recursion properties

I am trying to create a List of properties for objects. I can create a list for basic objects just fine, but if I have a situation where type object A contains a property of type object B which co...

how to change url without changing browser history

javascript html5 browser-history

Until now, I only know that if I want to change URL without reloading the whole page i have to use HTML browser history API.