我正在尝试使用链接发布用户IP地址以跟踪IP位置,我有以下PHP代码。我想在此http://whatismyipaddress.com/ip/108.44.33.225
<?php
if(isset($_POST['submit'])){
$to = "email@example.com";
$from = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ip=$_SERVER['REMOTE_ADDR'];
$subject = "Email IP submission as link";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message .= "IP Address:" <a href="http://whatismyipaddress.com/ip/. $ip .">. $ip</a>";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you ";
}
?>
答案 0 :(得分:1)
您的代码存在串联问题,请尝试使用
$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/".$ip."'>$ip</a>";
而不是
$message .= "IP Address:" <a href="http://whatismyipaddress.com/ip/. $ip .">. $ip</a>";
答案 1 :(得分:1)
请更正此行:
$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/". $ip ."'>". $ip."</a>";
或者你可以尝试
$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/$ip'>$ip</a>";