0

Im building a mailing contact form for my site. Its PHP.

I want to know my visitors Screen Width and Height so Ive tried adding the Scripts to my $variable =; But Ive had no luck. Every email sends the variable as etc rather using the code to give me a result.

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

Not having any luck. Could someone let me know my error? Cheers

  • At the time of rendering the form, you could write screen dimensions to hidden input fields which you can then get with `$_POST['screen_width']` and `$_POST['screen_height']` – Junaid Jul 08 '17 at 08:32
  • You mean do an – Sage Woodhouse Jul 08 '17 at 08:37
  • As far as i remember you need to open php tag with – Saad Suri Jul 08 '17 at 08:44
  • 1
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – jmattheis Jul 08 '17 at 08:46
  • You need to learn how JS works. No necessarily will this work ``. You can do this, `` then at footer, after page load, try this `` – Junaid Jul 08 '17 at 08:56
  • Ive tried what you said Junaid - I created a hidden input id=screen-width and name=screen-width. Added the script last on my page but still within the body. I also created a variable in my – Sage Woodhouse Jul 08 '17 at 09:17

1 Answers1

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>";
    }
?>
Junaid
  • 1,270
  • 3
  • 14
  • 33
Palani Samy
  • 169
  • 9
  • 2
    Please take a look at [How to write a good answer?](https://stackoverflow.com/help/how-to-answer) – Junaid Jul 08 '17 at 12:05