今天,我正在处理客户邮件表格,然后几次收到此通知。请任何人为我提供解决此问题的正确方法。
<?php
if(isset($_REQUEST['Submit']))
{
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$movingfrom = $_REQUEST['movingfrom'];
$movingto= $_REQUEST['movingto'];
$describe = $_REQUEST['describe'];
$weburl = $_REQUEST['weburl'];
$url =$_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
$sub="Enquiry Mail from : ".$_REQUEST['email'];
$from=$_REQUEST['email'];
}
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
if(($name == NULL) &&( $name== ""))
{
echo "Name is Mandatory <br>";
}
if(($email == NULL) &&($email == ""))
{
echo "Email is Mandatory <br>";
}
/*
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
echo "Valid Email is Mandatory <br>";
}
*/
if(($phone == NULL) &&($phone == ""))
{
echo "Phone No. is Mandatory <br>";
}
if(($movingfrom == NULL) &&($movingfrom == ""))
{
echo "Moving From City is Mandatory <br>";
}
if(($movingto == NULL) &&($movingto == ""))
{
echo "Moving To City is Mandatory <br>";
}
if( (($email != NULL) && ($email != "")) && (($name != NULL) && ($name != "")) && (($phone != NULL) && ($phone != "")) && (($movingfrom != NULL) && ($movingfrom != ""))&& (($movingto != NULL) && ($movingto != "")) )
{
$msg.="----------------------------------------------------------------\n";
$msg.="From:-\n";
$msg.="Name :$name\n";
$msg.="Mobile :$phone\n";
$msg.="Email :$email\n";
$msg.="Moving From :$movingfrom\n";
$msg.="Moving to :$movingto\n";
$msg.="----------------------------------------------------------------\n\n";
$msg.="Advertisement :-\n";
$msg.="$describe\n";
$msg.="REFERRER : $url\n";
$msg.="IP Address: " . getUserIpAddr();
$headers = "From: ${email}\n Reply-To: ${email}";
mail("abc@xyx.in","Enquiry Mail from: xyz", "$msg","From:$email");
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from old browser\n\n";
echo "function redirect() {\n";
echo "window.location = \"" . "http://localhost/thanks" . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
echo "-->\n";
echo "</script>\n";
}
else
{
header("location:localhost/index.php");
}
?>
注意:未定义的变量:第59行的quote.php中的味精
注意:未定义索引:第10行上的weburl quote.php
我发现了上述问题。 请任何人帮助我解决此问题。
答案 0 :(得分:0)
在连接之前,您需要像$msg
这样在代码$msg = ''
的开头进行定义...
$msg.="----------------------------------------------------------------\n";
您正在此处将其串联起来,但之前没有在任何地方定义它...
对于isset,您需要在使用数组值之前检查它是否已设置...
if(isset( $_REQUEST['weburl'])){
$weburl = $_REQUEST['weburl'];
}
答案 1 :(得分:0)
很简单。
我正在更新代码,您可以复制并粘贴它。
<?php
if(isset($_REQUEST['Submit']))
{
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$movingfrom = $_REQUEST['movingfrom'];
$movingto= $_REQUEST['movingto'];
$describe = $_REQUEST['describe'];
if(isset($_REQUEST['weburl']) && $_REQUEST['weburl']!=''){
$weburl = $_REQUEST['weburl'];
}else{
$weburl = '';
}
$url =$_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
$sub="Enquiry Mail from : ".$_REQUEST['email'];
$from=$_REQUEST['email'];
}
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
if(($name == NULL) &&( $name== ""))
{
echo "Name is Mandatory <br>";
}
if(($email == NULL) &&($email == ""))
{
echo "Email is Mandatory <br>";
}
/*
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
echo "Valid Email is Mandatory <br>";
}
*/
if(($phone == NULL) &&($phone == ""))
{
echo "Phone No. is Mandatory <br>";
}
if(($movingfrom == NULL) &&($movingfrom == ""))
{
echo "Moving From City is Mandatory <br>";
}
if(($movingto == NULL) &&($movingto == ""))
{
echo "Moving To City is Mandatory <br>";
}
$msg="";
if( (($email != NULL) && ($email != "")) && (($name != NULL) && ($name != "")) && (($phone != NULL) && ($phone != "")) && (($movingfrom != NULL) && ($movingfrom != ""))&& (($movingto != NULL) && ($movingto != "")) )
{
$msg.="----------------------------------------------------------------\n";
$msg.="From:-\n";
$msg.="Name :$name\n";
$msg.="Mobile :$phone\n";
$msg.="Email :$email\n";
$msg.="Moving From :$movingfrom\n";
$msg.="Moving to :$movingto\n";
$msg.="----------------------------------------------------------------\n\n";
$msg.="Advertisement :-\n";
$msg.="$describe\n";
$msg.="REFERRER : $url\n";
$msg.="IP Address: " . getUserIpAddr();
$headers = "From: ${email}\n Reply-To: ${email}";
mail("abc@xyx.in","Enquiry Mail from: xyz", "$msg","From:$email");
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from old browser\n\n";
echo "function redirect() {\n";
echo "window.location = \"" . "http://localhost/thanks" . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
echo "-->\n";
echo "</script>\n";
}
else
{
header("location:localhost/index.php");
}
?>
答案 2 :(得分:0)
像这样修改您的代码,它将对您有用。
<?php
if(isset($_REQUEST['Submit']))
{
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$movingfrom = $_REQUEST['movingfrom'];
$movingto= $_REQUEST['movingto'];
$describe = $_REQUEST['describe'];
if(isset($_REQUEST['weburl']))
$weburl = $_REQUEST['weburl'];
$url =$_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
$sub="Enquiry Mail from : ".$_REQUEST['email'];
$from=$_REQUEST['email'];
}
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
if(($name == NULL) &&( $name== ""))
{
echo "Name is Mandatory <br>";
}
if(($email == NULL) &&($email == ""))
{
echo "Email is Mandatory <br>";
}
/*
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
echo "Valid Email is Mandatory <br>";
}
*/
if(($phone == NULL) &&($phone == ""))
{
echo "Phone No. is Mandatory <br>";
}
if(($movingfrom == NULL) &&($movingfrom == ""))
{
echo "Moving From City is Mandatory <br>";
}
if(($movingto == NULL) &&($movingto == ""))
{
echo "Moving To City is Mandatory <br>";
}
if( (($email != NULL) && ($email != "")) && (($name != NULL) && ($name != "")) && (($phone != NULL) && ($phone != "")) && (($movingfrom != NULL) && ($movingfrom != ""))&& (($movingto != NULL) && ($movingto != "")) )
{
$msg = ""; $msg.="----------------------------------------------------------------\n";
$msg.="From:-\n";
$msg.="Name :$name\n";
$msg.="Mobile :$phone\n";
$msg.="Email :$email\n";
$msg.="Moving From :$movingfrom\n";
$msg.="Moving to :$movingto\n";
$msg.="----------------------------------------------------------------\n\n";
$msg.="Advertisement :-\n";
$msg.="$describe\n";
$msg.="REFERRER : $url\n";
$msg.="IP Address: " . getUserIpAddr();
$headers = "From: ${email}\n Reply-To: ${email}";
mail("abc@xyx.in","Enquiry Mail from: xyz", "$msg","From:$email");
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from old browser\n\n";
echo "function redirect() {\n";
echo "window.location = \"" . "http://localhost/thanks" . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
echo "-->\n";
echo "</script>\n";
}
else
{
header("location:localhost/index.php");
}
?>
对所有请求变量使用Isset,这样您就永远不会得到任何通知,因为有些值没有到来。
希望它会为您提供帮助。
答案 3 :(得分:0)
- 您需要初始化
$msg
变量。- 为
isset
编写$_REQUEST['weburl']
条件。.
您更新后的代码,例如:
<?php
if(isset($_REQUEST['Submit']))
{
$msg='';
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$movingfrom = $_REQUEST['movingfrom'];
$movingto= $_REQUEST['movingto'];
$describe = $_REQUEST['describe'];
if(isset($_REQUEST['weburl'])){
$weburl = $_REQUEST['weburl'];
}else{
$weburl ='';
}
$url =$_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
$sub="Enquiry Mail from : ".$_REQUEST['email'];
$from=$_REQUEST['email'];
}
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
if(($name == NULL) &&( $name== ""))
{
echo "Name is Mandatory <br>";
}
if(($email == NULL) &&($email == ""))
{
echo "Email is Mandatory <br>";
}
/*
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
echo "Valid Email is Mandatory <br>";
}
*/
if(($phone == NULL) &&($phone == ""))
{
echo "Phone No. is Mandatory <br>";
}
if(($movingfrom == NULL) &&($movingfrom == ""))
{
echo "Moving From City is Mandatory <br>";
}
if(($movingto == NULL) &&($movingto == ""))
{
echo "Moving To City is Mandatory <br>";
}
if( (($email != NULL) && ($email != "")) && (($name != NULL) && ($name != "")) && (($phone != NULL) && ($phone != "")) && (($movingfrom != NULL) && ($movingfrom != ""))&& (($movingto != NULL) && ($movingto != "")) )
{
$msg.="----------------------------------------------------------------\n";
$msg.="From:-\n";
$msg.="Name :$name\n";
$msg.="Mobile :$phone\n";
$msg.="Email :$email\n";
$msg.="Moving From :$movingfrom\n";
$msg.="Moving to :$movingto\n";
$msg.="----------------------------------------------------------------\n\n";
$msg.="Advertisement :-\n";
$msg.="$describe\n";
$msg.="REFERRER : $url\n";
$msg.="IP Address: " . getUserIpAddr();
$headers = "From: ${email}\n Reply-To: ${email}";
mail("abc@xyx.in","Enquiry Mail from: xyz", "$msg","From:$email");
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from old browser\n\n";
echo "function redirect() {\n";
echo "window.location = \"" . "http://localhost/thanks" . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
echo "-->\n";
echo "</script>\n";
}
else
{
header("location:localhost/index.php");
}
?>