【问题标题】:Some PHP variables not appearing when contact us form is used使用联系我们表单时,一些 PHP 变量未出现
【发布时间】: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 的建议。

标签: php forms contact


【解决方案1】:

您的代码:

$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  = "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";

根据您在问题中的解释,我认为您有几个字符串连接错误。

【讨论】:

  • 感谢您对代码的编辑,我现在将尝试并报告发生的情况。
【解决方案2】:

以下几行中=前面的点缺失

$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  .= "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";

【讨论】:

  • 感谢您的建议,不胜感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-26
  • 2020-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-30
相关资源
最近更新 更多