dtzk85937 2016-05-10 06:25
浏览 27

未知的发件人PHP

I created a form with a processing PHP file. Everything works fine. I receive the mail but it's from "Unknow sender" in Gmail. Why please ?

I would like to see in my email box the name and the firstname of the person who fills the form. What's wrong in my code ?

<?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条回答 默认 最新

  • duandianzhong8315 2016-05-10 06:43
    关注

    $mailer->From = $from; here for the $from variable, you have to get the form value as follows,

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

    Here is the complete code

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭