我如何在以下代码中使用$ message语句中的函数

时间:2013-07-27 10:24:29

标签: php string function email

假设我有以下php代码,我需要在名为any_function的字符串中使用名为$someotherthing的函数,我该如何使用它,请帮助???我也可以在$something ...

中的函数内使用字符串($someotherthing
<?php

function any_function(){
   $something = "something";
}

$someotherthing="need to use the above function here, how can i?";

?>

我需要使用的实际代码如下,我需要使用visitor_country()中的$message函数

<?php
$fullName=$_REQUEST['fullName'];
$phnNumber=$_REQUEST['phnNumber'];
$enquery=$_REQUEST['enquery'];
$ipaddress = $_SERVER["REMOTE_ADDR"];
function visitor_country()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
    $result  = "Unknown";
    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));

    if($ip_data && $ip_data->geoplugin_countryName != null)
    {
        $result = $ip_data->geoplugin_countryName;
    }

    return $result;
}

 $to="digibeem@gmail.com";
   $subject = "Contact Us form Details";
   $message = "\nFull Name : ".$fullName."\n Phone Number:".$phnNumber."\n General Enquiry : ".$enquery."\n IP Address : ".$ipaddress."\n Country: visitor_country() ";
   $from="dbedu@digibeem.com";
    @mail($to,$subject,$message,"From:$from");
    @header("location:../index.php");
?>

1 个答案:

答案 0 :(得分:1)

只需像其他变量一样添加它:

$message = "\nFull Name : ".$fullName."\n Phone Number:".$phnNumber."\n General Enquiry : ".$enquery."\n IP Address : ".$ipaddress."\n Country: " . visitor_country();