将访客国家添加到PHP邮件中

时间:2013-08-01 21:32:34

标签: email phpmailer php

我有一个显示访客国家的脚本。我想将它添加到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");
}

?>

1 个答案:

答案 0 :(得分:0)

取消echo visitor_country();在你的ip脚本上面。它应该是没有回声的自己的脚本......然后:

PHPMail代码:

<?php
include("NAME_OF_VISITOR_COUNTRY_SCRIPT.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]    
Country: ".visitor_country()."
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");
}

?>