IP地址不会传递给电子邮件正文

时间:2015-06-14 16:57:20

标签: php email ip

我的php表单设置为从发件人中提取IP地址。 表单生成没有错误...收到测试电子邮件,但没有将IP地址传递给电子邮件正文。 我做错了什么? 这是php表单:

master

3 个答案:

答案 0 :(得分:1)

我认为不需要{$message_body .= '<p>IP Address: ' . $_POST['ipaddress'] . '</p>' to {$message_body .= '<p>IP Address: ' .get_client_ip_server() . '</p>'

    int main()
    {
        ifstream file("file.txt");
        if ( /*here comes the check if file is open*/ ) cout<<"File open successfully"; else cout<<"File couldn't be opened. Check if the file is not used by another program or if it exists";
    }

答案 1 :(得分:0)

function get_client_ip_server() { $ipaddress = ''; if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(!empty($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(!empty($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(!empty($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if(!empty($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; if语句

中尝试!empty()
// Function to download data to a file
function download(data, filename, type) {
    var file = new Blob([data], {type: type});
    if (window.navigator.msSaveOrOpenBlob) // IE10+
        window.navigator.msSaveOrOpenBlob(file, filename);
    else { // Others
        var a = document.createElement("a"),
                url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);  
        }, 0); 
    }
}

}

答案 2 :(得分:0)

对于新手来说,这个程序太复杂了。保持简单,以获得不太重要的数据。例如,获取ip

$ip = $_SERVER['REMOTE_ADDR'];

在需要ip的地方使用$ip