2017-07-08 204 views
0

Im爲我的網站構建郵件聯繫表單。它的PHP。將腳本插入到PHP變量中

我想知道我的訪問者屏幕寬度和高度,所以我試着將腳本添加到我的$變量=;但我沒有運氣。每個電子郵件發送變量等,而不是使用代碼給我一個結果。

<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>"; 
} 
?> 

沒有任何運氣。有人能讓我知道我的錯誤嗎? 乾杯

+0

在繪製表格時,你可以寫的屏幕尺寸爲隱藏輸入字段然後你就可以用得到'$ _ POST [「SCREEN_WIDTH」]'和'$ _ POST [「SCREEN_HEIGHT」]' – Junaid

+0

你的意思是做一個」/> –

+0

據我記得你需要打開php標籤與<?php不與<? @SageWoodhouse –

回答

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>"; 
    } 
?> 
+2

請看看[如何寫出一個好的答案?](https://stackoverflow.com/help/how-to-answer) – Junaid

相關問題