需要城市/州摘要联系表格

时间:2016-08-24 12:51:20

标签: php forms email

我的PHP联系表单工作正常,并在后续电子邮件中输出包括发件人IP地址在内的所有信息。我在编写PHP表单时遇到问题,以便在表单生成的电子邮件中接收发件人的城市和州。

我已经尝试了几个代码段,但我得到的最多的是表单上方网页上的城市和州输出。我需要在电子邮件中使用它。寻找免费服务。

PHP表格

<?php
include 'contact_config.php';
session_start();
error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'functions.php';

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$level = stripslashes($_POST['level']);
$age = stripslashes($_POST['age']);
$drums = stripslashes($_POST['drums']);
$referral = stripslashes($_POST['referral']);
$city = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
$subject = " Website Inquiry";
$message = "

Name:  ".$_POST['name']
."

E-mail Address:  ".$_POST['email']
."

Level:  ".$_POST['level']
."

Age:  ".$_POST['age']
."

Drums:  ".$_POST['drums']
."

Referral:  ".$_POST['referral']
."

Message:  ".$_POST['content']
."

City:  ".$_POST['city']
."

IP Address:  ". $_SERVER['REMOTE_ADDR'];

$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

if(isset($_SESSION['captcha_keystring']) && strtolower($_SESSION['captcha_keystring']) != strtolower($_POST['captcha']))
{
$error .= "Incorrect captcha numbers.<br />";
}

if(!$error)
{

$mail = mail(WEBMASTER_EMAIL, $subject, $message,
 "From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());

if($mail)
{
echo 'OK';
}

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
?>

1 个答案:

答案 0 :(得分:0)

查看代码的这一部分:

$message = "

Name:  ".$_POST['name']
."

E-mail Address:  ".$_POST['email']
."

Level:  ".$_POST['level']
."

Age:  ".$_POST['age']
."

Drums:  ".$_POST['drums']
."

Referral:  ".$_POST['referral']
."

Message:  ".$_POST['content']
."

City:  ".$_POST['city']
."

IP Address:  ". $_SERVER['REMOTE_ADDR'];

您正在将变量连接到新变量。只需将$ _POST ['state']或你如何调用这些字段添加到这个大变量中。因为你已经添加了$ _POST ['city']。

因此,如果电子邮件中没有显示,您发送的字段的名称会有所不同。