未知发件人PHP


Unknown Sender PHP

我用一个处理PHP文件创建了一个表单。一切都很好。我收到了邮件,但它来自Gmail中的"未知发件人"。为什么请?

我想在我的邮箱里看到填写表格的人的名字和名字。我的代码出了什么问题?

<?php session_start();
if($_POST['Submit'])
{
if($_SESSION['security_code'] == $_POST['security_code']) 
{
extract($_POST);
ini_set("extension=php_openssl.dll",true);
ini_set("extension=php_smtp.dll",true);
include_once("phpmailer/class.phpmailer.php");
function calltoMailer($from,$to,$cc,$subject,$message)
{
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->FromName = $_POST['email'];            
$mailer->From = $from;
$mailer->AddAddress($to);
$mailer->AddAddress($cc);
$mailer->Subject = $subject;
$mailer->ContentType="text/html";
$mailer->Body = $message;//'body 
try
{
if($mailer->Send())
{
$msgsend =1; 
}
else
{
$msgsend =0; 
}
}
catch(Excpetion $e)
{
print($mailer->ErrorInfo);
}
return $msgsend;
}   
$to=$_POST['ToEMail'];
$cc=$_POST['CcEMail'];
$subject=$_POST['subject'].$_POST['ResEnq'];
$message="<table width='800' cellspacing='1' cellpadding='8' border='1' align='center' style='color:#5f5f5f;font-family:Arial, Helvetica, sans-serif;font-size:12px;'><tr style='background-color:#72abe4;'><td colspan='2' align='center' style='color:#ffffff'>Enquiry From Hotel Kailas.</td></tr>";
//$message="";
if($_POST['ResEnq'] != '')
$message .= "<tr><td>Type : </td><td>".$_POST['ResEnq']."</td></tr>";
if($_POST['name'] != '')
$message .= "<tr><td>Name : </td><td>".$_POST['name']."</td></tr>";
if($_POST['address'] != '')
$message .= "<tr><td>Address : </td><td>".$_POST['address']."</td></tr>";
if($_POST['phone'] != '')
$message .= "<tr><td>Phone : </td><td>".$_POST['phone']."</td></tr>";
if($_POST['fax'] != '')
$message .= "<tr><td>Fax : </td><td>".$_POST['fax']."</td></tr>";
if($_POST['email'] != '')
$message .= "<tr><td>Email ID : </td><td>".$_POST['email']."</td></tr>";
if($field == 'email'){ $from = $_POST[$field_id]; }
if($_POST['txtFromDate'] != '')
$message .= "<tr><td>Date of Arrival : </td><td>".$_POST['txtFromDate']."</td></tr>";
if($_POST['txtToDate'] != '')
$message .= "<tr><td>Date of Departure : </td><td>".$_POST['txtToDate']."</td></tr>";
if($_POST['No_Of_Persons'] != '')
$message .= "<tr><td>Number of Persons : </td><td>".$_POST['No_Of_Persons']."</td></tr>";
if($_POST['child_yrs'] != '')
$message .= "<tr><td>Children below 10 yrs : </td><td>".$_POST['child_yrs']."</td></tr>";
if($_POST['Type_Of_Cottage'] != '')
$message .= "<tr><td>Type of Cottages/Rooms (Cost in INR / Rs. Per Day) : </td><td>".$_POST['Type_Of_Cottage']."</td></tr>";
if($_POST['No_Of_Cottage'] != '')
$message .= "<tr><td>Number of Cottages Required : </td><td>".$_POST['No_Of_Cottage']."</td></tr>";
$client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
$json2 = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$client_ip."");
$data = unserialize($json2);
if($client_ip != '')
$message .= "<tr><td>Client Details : </td><td>".$client_ip." , ".$data['geoplugin_city']. " , " .$data['geoplugin_region']." , ".$data['geoplugin_countryName'];
$message .="</td></tr></table>";
$errorMessage=calltoMailer($txtEmail,$to,$cc,$subject,$message);
$errorMessage = "Your message has been sent to the Webmaster. We will get back to you soon.";
require($_POST['redirect']);
}
else
{
extract($_POST);
$errorMessage = "Security code does not match.";
unset($_SESSION['security_code']);
require($_POST['redirectIssue']);   
}
}
?>

$mailer->From = $from;对于$from变量,您必须获得如下形式的值,

$from = $_POST['from field name'];

这是完整的代码

<?php session_start();
if($_POST['Submit'])
{
if($_SESSION['security_code'] == $_POST['security_code']) 
{
extract($_POST);
ini_set("extension=php_openssl.dll",true);
ini_set("extension=php_smtp.dll",true);
include_once("phpmailer/class.phpmailer.php");
function calltoMailer($from,$to,$cc,$subject,$message)
{
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->FromName = $_POST['email'];            
$mailer->From = $from;
$mailer->AddAddress($to);
$mailer->AddAddress($cc);
$mailer->Subject = $subject;
$mailer->ContentType="text/html";
$mailer->Body = $message;//'body 
try
{
if($mailer->Send())
{
$msgsend =1; 
}
else
{
$msgsend =0; 
}
}
catch(Excpetion $e)
{
print($mailer->ErrorInfo);
}
return $msgsend;
}   
$to=$_POST['ToEMail'];
$cc=$_POST['CcEMail'];
$from = $_POST['name'];
$subject=$_POST['subject'].$_POST['ResEnq'];
$message="<table width='800' cellspacing='1' cellpadding='8' border='1' align='center' style='color:#5f5f5f;font-family:Arial, Helvetica, sans-serif;font-size:12px;'><tr style='background-color:#72abe4;'><td colspan='2' align='center' style='color:#ffffff'>Enquiry From Hotel Kailas.</td></tr>";
//$message="";
if($_POST['ResEnq'] != '')
$message .= "<tr><td>Type : </td><td>".$_POST['ResEnq']."</td></tr>";
if($_POST['name'] != '')
$message .= "<tr><td>Name : </td><td>".$_POST['name']."</td></tr>";
if($_POST['address'] != '')
$message .= "<tr><td>Address : </td><td>".$_POST['address']."</td></tr>";
if($_POST['phone'] != '')
$message .= "<tr><td>Phone : </td><td>".$_POST['phone']."</td></tr>";
if($_POST['fax'] != '')
$message .= "<tr><td>Fax : </td><td>".$_POST['fax']."</td></tr>";
if($_POST['email'] != '')
$message .= "<tr><td>Email ID : </td><td>".$_POST['email']."</td></tr>";
if($field == 'email'){ $from = $_POST[$field_id]; }
if($_POST['txtFromDate'] != '')
$message .= "<tr><td>Date of Arrival : </td><td>".$_POST['txtFromDate']."</td></tr>";
if($_POST['txtToDate'] != '')
$message .= "<tr><td>Date of Departure : </td><td>".$_POST['txtToDate']."</td></tr>";
if($_POST['No_Of_Persons'] != '')
$message .= "<tr><td>Number of Persons : </td><td>".$_POST['No_Of_Persons']."</td></tr>";
if($_POST['child_yrs'] != '')
$message .= "<tr><td>Children below 10 yrs : </td><td>".$_POST['child_yrs']."</td></tr>";
if($_POST['Type_Of_Cottage'] != '')
$message .= "<tr><td>Type of Cottages/Rooms (Cost in INR / Rs. Per Day) : </td><td>".$_POST['Type_Of_Cottage']."</td></tr>";
if($_POST['No_Of_Cottage'] != '')
$message .= "<tr><td>Number of Cottages Required : </td><td>".$_POST['No_Of_Cottage']."</td></tr>";
$client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
$json2 = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$client_ip."");
$data = unserialize($json2);
if($client_ip != '')
$message .= "<tr><td>Client Details : </td><td>".$client_ip." , ".$data['geoplugin_city']. " , " .$data['geoplugin_region']." , ".$data['geoplugin_countryName'];
$message .="</td></tr></table>";
$errorMessage=calltoMailer($txtEmail,$to,$cc,$subject,$message);
$errorMessage = "Your message has been sent to the Webmaster. We will get back to you soon.";
require($_POST['redirect']);
}
else
{
extract($_POST);
$errorMessage = "Security code does not match.";
unset($_SESSION['security_code']);
require($_POST['redirectIssue']);   
}
}
?>

您可以使用重建

$mailer->setFrom($_POST['email'], $from);