2016-05-10 10 views
0

処理PHPファイルでフォームを作成しました。すべてうまく動作します。私はメールを受け取るが、それはGmailの "Unknow sender"からのものだ。どうして?不明な送信者PHP

私は電子メールボックスに、フォームを記入する人の名前とファーストネームを見たいと思います。私のコードで何が間違っていますか?

$from変数はこちら
<?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

オンライン '$ errorMessage = calltoMailer($ txtEmail、$ to、$ cc、$件名、$メッセージ); '、' $ txtEmail'変数は定義されていません。 – Apb

答えて

0

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

が動作しない、まだ問題がある –

0

は、あなたがしてそれを再構築することができます:

$mailer->setFrom($_POST['email'], $from); 
関連する問題