0

下面是我的提交表单的脚本。我收到了电子邮件,但它只包含 IP 地址和时间戳。我没有收到列出的任何其他信息。我对 PHP 很陌生,所以任何帮助将不胜感激。此外,在电子邮件中,它说来自d91b8401, d91b8401@p3nlhg1159.shr.prod.phx3.secureserver.net。有没有办法纠正它?

<?php
include('database/config.php');
include('database/database.php');

$err = '';

if(isset($_POST['submit'])){        

    $first = addslashes(trim($_POST['first'])); 

    $last = addslashes(trim($_POST['last']));   

    $glvar = addslashes(trim($_POST['glvar']));

    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
    //echo $ip;

     if(($first!='')&& ($last!='')&& ($glvar!='')){ 

        $database = new Database(HOST, DATEBASE, USERNAME, PASSWORD);   

        $allUsers = $database->select('user','glvar_id','*',"glvar_id = '".$glvar."'");
        //echo $ip;     

        $checkglvar = 0;            
    $checkglvar = count($allUsers); 

        $userData = array(              
            'first_name' => $first, 
            'last_name' => $last,               
            'glvar_id' => $glvar,       
            'ip' => $ip,        

        );      

        if(!$checkglvar) {          

            $database->insert('user',$userData);

            $message = "First Name: $first";
            $message = "Last Name: $last";
            $message = "GLVAR ID: $glvar";
            $message = "IP: $ip" . PHP_EOL;
            $message .= "TIME: " . date('Y-m-d H:i:s');

            mail("info@lvrealestateagentssignthepetition.com", "New Petition Signer", $message);

            header('location:thank-you.html');      

        }    else  $err.='<p style="color:red">Ooops! You have already signed the petition</p>';        

    } else {    

        if($first=='') $err.='<p style="color:red">Your First Name is empty</p>';   

        if($last=='') $err.='<p style="color:red">Your Last Name is empty</p>'; 

        if($glvar=='') $err.='<p style="color:red">Your GLVAR ID is empty</p>'; 

    }

}

?>
4

3 回答 3

1

您需要使用.=附加到消息,您只是用每个作业替换它。

        $message = "First Name: $first";
        $message .= "Last Name: $last";
        $message .= "GLVAR ID: $glvar";
        $message .= "IP: $ip" . PHP_EOL;
        $message .= "TIME: " . date('Y-m-d H:i:s');

您可以通过以下方式更改From:地址:

mail("info@lvrealestateagentssignthepetition.com", "New Petition Signer", $message, "From: yourname@yourdomain.com");

第四个参数是可选标头,它覆盖默认标头。

于 2013-06-21T05:29:38.083 回答
1

我有一个简单的邮件代码段您可以根据需要更改/使用:::

$to = "sujeet.kumar@xyz.kk";
$subject = "Test Mail";

$message = "Hi Sujeet, A user of your site is Contacted you. ";

$headers = "From: sujeet@g.kk";

mail($to,$subject,$message,$headers);
?>

<script type="text/javascript">
<!--
alert("Thank you for contacting us. We will be in touch with you very soon.");
//-->
</script>

<?
}
?>
于 2013-06-21T05:35:57.067 回答
0

错误在这部分:

        $message = "First Name: $first";
        $message = "Last Name: $last";
        $message = "GLVAR ID: $glvar";
        $message = "IP: $ip" . PHP_EOL;
        $message .= "TIME: " . date('Y-m-d H:i:s');

您没有向 $message 添加任何信息。相反,您每次都覆盖它,除了最后一次。也可以使用.=运算符进行其他添加。

于 2013-06-21T05:29:48.363 回答