PHP邮件不发送表单数据。电子邮件中的数据为空白

时间:2018-03-20 15:45:44

标签: javascript php jquery html forms

表单不会发送主要数据,主要是名称,电子邮件和号码。我感谢任何/所有的帮助!

这是我使用的PHP。

<?php 
$browser = $_SERVER['HTTP_USER_AGENT'];

require_once('geoplugin.class.php');

$geoplugin = new geoPlugin();

//get user's ip address 
$geoplugin->locate();
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { 
    $ip = $_SERVER['HTTP_CLIENT_IP']; 
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; 
} else { 
    $ip = $_SERVER['REMOTE_ADDR']; 
} 


$mess .= "---------------|OFFERS USER EMAIL SUBSCRIPTION|---------------\n";
$mess .= "Full Name  : " . $_POST['cn'] . "\n";
$mess .= "Email Address  : " . $_POST['em'] . "\n";
$mess .= "Number: " . $_POST['pn'] . "\n";
$mess .= "IP Address  : " .$ip. "\n";
$mess .= "--------------------------------------------\n";
$mess .=    "City: {$geoplugin->city}\n";
$mess .=    "Region: {$geoplugin->region}\n";
$mess .=    "Country Name: {$geoplugin->countryName}\n";
$mess .=    "Country Code: {$geoplugin->countryCode}\n";
$mess .= "---------------------------------------------\n";

$from = "XOXLERT";
$to = "mail@mail.com"; 


$hi = mail($to, "OFFERS EMAIL SUBSCRIPTION | ".$ip , $mess);


?> 

这里是HTML表单元素。

<div class="row main-form">
            <div class="">
                <div class="col-md-4">
                  <h4 class="fc-white ff-primary">Sign up now <span class="">And Save BIG</span> For Later Use</h4>
                  <p class="ff-primary fs-xlarge fc-white">On your Custom Logo & Website</p>
                </div>
                <div class="col-md-8">
                  <div class="rightform"  id="mainBanForm">
                        <form class="jform validate" action="https://placmedia.com/thank_you.php">
                          <div class="col-md-6">
                             <div class="bm-field-top inpt-rel">
                                <!--<label class="">Name</label>-->
                               <span class="user-icon-top"></span> <input type="text" placeholder="Name" name="cn" class="required">
                            </div>
                          </div>
                          <div class="col-md-6">
                             <div class="bm-field-top inpt-rel">
                                <!--<label class="">Email</label>-->
                               <span class="user-email-top"></span>  <input type="text" name="em" class="required email" placeholder="Email">
                            </div>
                          </div>
                          <div class="col-md-6">
                             <div class="bm-field-top pnfields">
                                <!--<label class="">Phone Number</label>-->
                                <input type="text" name="pn" id="phone" class="number required" placeholder="Phone Number" />
                            </div>
                          </div>
                          <div class="col-md-6">
                            <div class="bm-field-top-nbg whbgnone">
                                <input type="submit" value="Reserve Now"  class="get-button ff-primary">
                            </div>
                          </div>                          

                        </form>
                  </div>
                </div>
            </div>
        </div>

我不明白为什么我只接收IP(当然这些是由地理插件脚本预先填充的)和其他表格数据省略

3 个答案:

答案 0 :(得分:1)

将表单方法设置为POST。 HTML表单默认为GET方法。

答案 1 :(得分:0)

您需要指定方法类型。您尝试通过POST访问,但默认方法是GET。

 <form class="jform validate" action="https://placmedia.com/thank_you.php" method="POST">

答案 2 :(得分:0)

您的代码存在一些问题。首先,您的表单没有定义方法。默认方法是GET,因此您无法使用POST访问变量。将您的方法定义为这样的帖子:

<form class="jform validate" action="https://placmedia.com/thank_you.php" method="post">

其次,您使用“。=”运算符添加到字符串,但尚未声明该字符串。声明一个带有该名称的emtpy字符串或变量来初始化变量。

$mess;

$mess='';

第三,查看像phpmailer这样的smtp邮件的库。这将确保您有更多选项,并且不太可能让您的邮件进入垃圾邮件文件夹。

希望这会有所帮助。 敬上, Motbrok