【发布时间】:2015-12-28 00:02:24
【问题描述】:
以下是我的联系表单的 php 代码,该网站目前处于活动状态,当我使用表单使用联系我们表单发送查询时,并非所有信息都能通过:
在我收到的电子邮件中,通过的唯一信息是 $subject 和消息($name 想在 $move 上移动。\r\n\n";)。没有其他数据客户端电子邮件中列出了网站上的输入。我查看了代码,但似乎找不到问题所在。
我将不胜感激。
<?php
if(!$_POST) exit;
$to = 'mydomain@email.com';
$name = $_POST['txtname'];
$email = $_POST['txtemail'];
$phone = $_POST['txtphone'];
$comp = $_POST['txtcomp'];
$emp = $_POST['txtemp'];
$move = $_POST['txtmove'];
$comment = $_POST['txtmessage'];
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name.\r\n\n";
$msg .= "$comment\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg = "You can call $name on $phone.\r\n\n";
$msg = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg = "$name would like to move in on $move.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(@mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<span class='success-msg'>Thanks for Contacting Us, We will call back to you soon.</span>";
}
else
{
echo "<span class='error-msg'>Sorry your message was not sent, Please try again.</span>";
}
?>
感谢您的回复和建议,以下是表单的 HTML:
<div id="map"></div>
<div class="dt-sc-margin50"></div>
<div class="container">
<div class="column dt-sc-three-fourth first">
<div class="hr-title">
<h3>Request A Call Back</h3>
<div class="title-sep">
</div>
</div>
<form method="post" class="dt-sc-contact-form" action="php/send.php" name="frmcontact">
<div class="column dt-sc-one-third first">
<p> <span class="auto-style2">Your Name</span><span> <input type="text" placeholder="Name*" name="txtname" maxlength="25" value="" required /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Your Email Address<span> <input type="email" placeholder="Email*" name="txtemail" value="" required /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Your Contact Number <span> <input type="text" placeholder="Phone" name="txtphone" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third first">
<p><span class="auto-style2">Company Name <span> <input type="text" placeholder="Company Name" name="txtcomp" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">No Of Employees <span> <input type="number" placeholder="No Of Employees" name="txtemp" value="" /> </span> </p>
</div>
<div class="column dt-sc-one-third">
<p><span class="auto-style2">Move In Date <span> <input type="date" placeholder="Move In Date" name="txtmove" value="" /> </span> </p>
</div>
<p> <span class="auto-style2">Please describe below what kind of office you are looking for,we will reply to your query on the same day.<textarea placeholder="Message*" name="txtmessage" maxlength "750" required ></textarea> </p>
<p> <input type="submit" value="Send Message" name="submit" /> </p>
</form>
<div id="ajax_contact_msg"></div>
</div>
2015 年 1 月 10 日更新
大家好
我根据 Dp 和 sebastianbrosch 的建议进行了更改。该网站现在再次上线,但是当我尝试发送表单时,它显示“页面保存失败”。下面是更新后的php代码,html联系我们页面文件保持不变。
您好,抱歉,我已经粘贴了 php 代码,但由于某种原因,它没有出现在帖子中。我会再试一次。
<?php
if(!$_POST) exit;
$to = 'mydomain@email.com';
$name = $_POST['txtname'];
$email = $_POST['txtemail'];
$phone = $_POST['txtphone'];
$comp = $_POST['txtcomp'];
$emp = $_POST['txtemp'];
$move = $_POST['txtmove'];
$comment = $_POST['txtmessage'];
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$subject = 'Office enquiry via domain.com from ' . $name . '.';
$msg = "You have been contacted by ".$name."\r\n\n";
$msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
$msg .= "You can call ".$name." on ".$phone.".\r\n\n";
$msg .= "$name has ".$emp." employees and the company name is ."$comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";
$msg .= $comment."\r\n\n";
$msg .= "---------------------------------------------------------------\r\n";
if(@mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{
echo "<span class='success-msg'>Thanks for Contacting Us, We have received your query and will be in touch soon.</span>";
}
else
{
echo "<span class='error-msg'>Sorry your message was not sent, Please try again or contact us via live chat.</span>";
}
?>
【问题讨论】:
-
你也应该出示表格
-
能否在问题中包含 HTML 表单?另外,您是否尝试在提交表单后执行
var_dump($_POST);以查看即将到来的数据? - -
最可能的原因是您没有为
$_POST变量使用正确的名称,或者表单上的字段没有name=""属性。 向我们展示表单 html 和/或在代码顶部添加print_r($_POST);,以便您可以查看$_POST中的内容 -
Club 由 Dp 和 sebastianbrosch 提供的解决方案。
-
感谢您的回复,我会尝试 Dp 和 sebastianbrosch 的建议。