将脚本插入PHP变量

时间:2017-07-08 08:26:14

标签: php jquery forms

我正在为我的网站建立一个邮寄联系表格。它的PHP。

我想知道我的访问者屏幕宽度和高度,所以我尝试将脚本添加到我的$ variable =;但我没有运气。每封电子邮件都会将变量作为等等发送,而不是使用代码给我一个结果。

<head><style>
<?
$screenwidth = '<script type="text/javascript">document.write(screen.availWidth);</script>';
?>
</style></head>
<body>

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST['submit']))

{
$ipadd = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$screen = "$screenwidth";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mobile = $_POST['mob'];
$address = $_POST['addr'];
$formcontent="$name \n$mobile \n$address \r\nMessage: $message \r\nBrowser: $agent \nIP: $ipadd \n $screen \r\n";
$recipient = "";
$subject = $_POST['subject'];
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

echo "<h3>Thank You!</h3><h4>Expect a response within 24 hours</h4>";
}
?>

没有运气。有人能告诉我我的错误吗? 干杯

1 个答案:

答案 0 :(得分:1)

<head>
    <style>
    </style>
</head>
<body>

<?php 
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    if(isset($_POST['submit'])) {
        $ipadd = $_SERVER['REMOTE_ADDR'];
        $agent = $_SERVER['HTTP_USER_AGENT'];

        $screen = '<script type="text/javascript">document.write(screen.availWidth);</script>';
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $mobile = $_POST['mob'];
        $address = $_POST['addr'];
        $formcontent="$name \n$mobile \n$address \r\nMessage: $message \r\nBrowser: 
        $agent \nIP: $ipadd \n $screen \r\n";
        $recipient = "";
        $subject = $_POST['subject'];
        $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
        echo "<h3>Thank You!</h3><h4>Expect a response within 24 hours</h4>";
    }
?>