我有一个显示访问者国家的脚本。我想将它添加到 PHPMail 中,但不知道该怎么做,因为它是由函数创建的。任何人都可以建议我以任何方式将其添加到 PHPMail 上,所以当他们提交联系表格时,我也会获得访问者国家/地区。
获取访问者国家脚本=
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;
}
echo visitor_country(); // Output Coutry name [Ex: United States]
?>
我的 PHPMail 代码-
<?php
//--Mail Server Setup----------------------------------
ini_set("SMTP", "mail.$_SERVER[SERVER_NAME]");
ini_set("smtp_port", 25);
ini_set("sendmail_from", "info@$_SERVER[SERVER_NAME]");
ini_set("memory_limit", "1024M");
//-----------------------------------------------------
if($_POST['submit']){
$email_msg="
Advertising Inquiries Request, Details Below:
Name: $_POST[name]
Company: $_POST[company]
Email: $_POST[email]
Phone: $_POST[phone]
Geo Targeting: $_POST[geo_targeting]
Website: $_POST[website]
Message: $_POST[message]
IP: ".$_SERVER['REMOTE_ADDR']."
";
$headers .= 'From: Arif Khan<arif@uposonghar.com>';
if(mail("arifkpi@gmail.com", "Advertising Inquiries", $email_msg, $headers));
header("location:index.html");
}
?>