Reputation: 21
I've been trying to test if I could send my IP to my email. It doesn't seem to work.
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta name="description" content="My Personal Website">
<meta name="keywords" content="MSHLondon, Sabri, Meeran">
<meta name="author" content="Sabri Meeran">
<link rel="shortcut icon" type="image/x-icon" href="mshLogo.ico">
<title>Test.</title>
</head>
<body>
<?php
$message = "IP Address: " . $_SERVER['REMOTE_ADDR'] . "\r\n";
mail('[email protected]', 'DataRecieved', $message);
?>
<span>Just a test.</span>
</body>
</html>
[Changed email, but everything else is the same]
It doesn't seem to send, even in spam.
Upvotes: 2
Views: 36
Reputation: 6780
The remote host will be blank - since you are running this from the command line.
That will be populated when a web request comes to the PHP application.
If you want the server IP, use $_SERVER['SERVER_ADDR']
UPDATE
$message = '<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta name="description" content="My Personal Website">
<meta name="keywords" content="MSHLondon, Sabri, Meeran">
<meta name="author" content="Sabri Meeran">
<link rel="shortcut icon" type="image/x-icon" href="mshLogo.ico">
<title>Test.</title>
</head>
<body>
<p>IP Address:'. $_SERVER['REMOTE_ADDR'] . '</p>
<span>Just a test.</span>
</body>
</html>';
mail('[email protected]', 'DataRecieved', $message);
Your code is not correct, try using that snippet instead.
Upvotes: 1