dongquanlin1885 2014-08-06 18:58
浏览 12
已采纳

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>
  • 写回答

1条回答 默认 最新

  • doubu5035 2014-08-06 19:04
    关注

    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'].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word