未知的发件人PHP

时间:2016-05-10 06:25:09

标签: php

我创建了一个带有处理PHP文件的表单。一切正常。我收到了邮件,但它来自" Unknow sender"在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']);   
}
}
?>

2 个答案:

答案 0 :(得分:0)

$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']);   
}
}
?>

答案 1 :(得分:0)

您可以使用以下方式重建:

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