PHP form not working in Internet Explorer

2019-07-27 12:04发布

问题:

I created this contact form, it works perfectly in firefox and chrome but in internet explorer it wont allow you to input text (clicking on the form fields does nothing) the submit button works but only sends a blank message because no text can be entered. Also when you press submit it tries to open mail.php in a firefox page, i am only testing locally on my pc could this be the issue?

PHP is this :

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $formcontent="This message has been generated from the Contact page \n Name: $name \n Phone: $phone \n Email: $email \n Message: $message";
    $recipient = "myemail@myemail.co.uk";
    $subject = "Enquiry From contact page";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    header('Location: ../contact2.html');
?>

HTML is:

<form id="form1" action="PHP/mail.php" method="post">
    <label>Name <span class="small">Add your name</span></label> 
    <input type="text" name="name"><br>
    <label>Email <span class="small">Enter a Valid Email</span></label> 
    <input type="text" name="email"><br>
    <label>Phone <span class="small">Add a Phone Number</span></label> 
    <input type="text" name="phone"><br>

    <br>
    <br>

    <label>Message <span class="small">Type Your Message</span></label> 
    <textarea name="message" rows="6" cols="25">
    </textarea><br>
    <button type="submit" value="Send" style="margin-top:15px;">Submit</button>
    <div class="spacer"></div>
</form>

回答1:

Based on purely on the form you have I was able to enter text in the form in Chrome, FireFox and IE8.

Take your html form code and place it in an independent file HTML file and test in IE to see if you get the same behavior.

Testing an HTML file will narrow the problem down to just checking the browser removing other variables like your PHP server or javascript.

-If you get the same issue: it is a IE issue independent to that PC.

-If you do not get the same issue: it may be a problem with your php configuration or javascript.

            <form id="form1" action="PHP/mail.php" method="post">
                <label>Name <span class="small">Add your name</span></label> <input type="text" name="name" /><br />
                <label>Email <span class="small">Enter a Valid Email</span></label> <input type="text" name="email" /><br />
                <label>Phone <span class="small">Add a Phone Number</span></label> <input type="text" name="phone" /><br />
                <br>
                <br>
                <label>Message <span class="small">Type Your Message</span></label> 
                <textarea name="message" rows="6" cols="25">
                </textarea><br>
                <button type="submit" value="Send" style="margin-top:15px;">Submit</button>
                <div class="spacer"></div>
            </form>


回答2:

You should be closing your tags, like so:

<input type="text" name="email" />

The same goes for your newline tags:

<br />

Any tag that doesn't require content in the middle should be closed like that. The image tag would be another example.

<img src="myimg.png" />

Also, I would use an button because I think it makes the code look cleaner:

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