PHP无法正常工作?

PHP无法正常工作?

问题描述:

I have this PHP code here, which should sent the Names, Email and comment of the user to an email. Although it doesn't seem to be working any more. I've been using this code as a basis for my contact form for many years. Now they're just not working.

Your message is being sent...
<?php


$emailSubject = 'A message from: '.$_POST['name'] .' '.'-'.' ' .'Email Adress: ' .$_POST['email'];
$webMaster = 'webmaster@gmail.com';


$name1 = $_POST['name1'];
$name2 = $_POST['name2'];
$email = $_POST['email'];
$sub = $_POST['sub'];
$comments = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
<b>First Name: $name1 </b><br> 
<b>Last Name: $name2 </b><br>
Email: $email <br>
Subject: $sub <br>
Comments: $comments <br>
EOD;

$headers = "From: $email
";
$headers .= "Content-type: text/html
";
$success = mail($webMaster, $emailSubject, $body,
$headers);

$theResults = <<<EOD
<html>
<head>
<title>Your message is being sent...</title>
<meta http-equiv="refresh" content="4;URL=http://www.google.co.uk">
<style type="text/css">
<!--

body {
background-color: #25EA5F;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #30489E;
text-decoration: none;
padding-top: 350px;
margin-left: 550px;
width: 800px;
}
-->
</style>
</head>

</html>
</body>
EOD;
echo "$theResults";
?>

It's very confusing and annoying. Messages when sent to Hotmail don't even appear, so that'll force the clients to get a new email because of it, and when sent to Google... Does it not accept $_POST or something?

This is what happens when I send a message to Google.

As you can see, the SCRIPT does work, it's just with G-mail none of the important information seems to show up, and on Hotmail the messages don't even send/appear!! Thanks for your help. Here is the HTML if needed.

<div class="contactwrap">
<div class="ContactInner">
<div class="ContactTitle">CONTACT US</div>

<form action="Scripts/contact.php" method="post">
  <div class="containboxes">

<span id="sprytextfield1">
<label for="text1"></label>
<input name="text1" type="text" class="inputstyle" id="name1" value="First Name"     size="5" maxlength="5" />
<span class="textfieldRequiredMsg"></span></span>

<span id="sprytextfield2">
<label for="text2"></label>
<input name="text2" type="text" class="inputright" id="name2" value="Last Name" />
<span class="textfieldRequiredMsg"></span></span>

<span id="sprytextfield3">
<label for="text3"></label>
<input name="text3" type="text" class="inputstyleBelow" id="email" value="E-mail Address" />
<span class="textfieldRequiredMsg"></span><span     class="textfieldInvalidFormatMsg">Invalid format.</span></span>

<span id="sprytextfield4">
<label for="text4"></label>
<input name="text4" type="text" class="inputrightBelow" id="sub" value="Message Subject" />
<span class="textfieldRequiredMsg"></span></span>

<span id="sprytextarea1">
<label for="textarea1"></label>
<textarea name="textarea1" cols="45" rows="5" class="inputstyleMsg" id="comments">Message Here</textarea>
<span id="countsprytextarea1">&nbsp;</span><span class="textareaRequiredMsg"></span>    <span class="textareaMinCharsMsg">Minimum number of characters not met.</span><span     class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span>


<div class="sendbtn"><input name="Submit message" type="submit" class="submitmail" value="" /></div>
</div>
</form>

</div>
</div>

Your form fields are incorrect. id is NOT used in form submission. the name parameter is. Since you've named your form fields as text1, text2, etc... but are looking for name1 and similar in your PHP code, you're trying to retrieve non-existent fields.

e.g. you have:

<input name="text1" type="text" class="inputstyle" id="name1" value="First Name"     size="5" maxlength="5" />
$_POST['name1'];

no, that field will actually be $_POST['text1'].