如何在php格式的IP地址之前添加链接地址


How add link address before the IP address in php form

我正在尝试发布带有跟踪IP位置链接的用户IP地址,我有下面的php代码。我想在这个http://whatismyipaddress.com/ip/108.44.33.225 的超链接中包括用户IP

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

请更正这一行:

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/". $ip ."'>". $ip."</a>";

或者你可以试试

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/$ip'>$ip</a>";

您的代码存在串联问题,试试这个,

$message .= "IP Address: <a href='http://whatismyipaddress.com/ip/".$ip."'>$ip</a>";

而不是

$message .= "IP Address:" <a href="http://whatismyipaddress.com/ip/. $ip .">. $ip</a>";