2017-06-21 8 views
-1

をフォームの苦情値を送信できませんでした。ここHTMLコードされる: - :https://pastebin.com/g0Cnh8iRHTMLスクリプトは、PHPスクリプトに

<?php 
require 'PHPMailerAutoload.php'; 


$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = '*******';       // SMTP password 
$mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 465;         // TCP port to connect to 
if(isset($_POST['n']) && isset($_POST['e']) && isset($_POST['m'])){ 
    $n = $_POST['n']; 
    $e = $_POST['e']; 
    $m = nl2br($_POST['m']); 
    $c = $_POST['complaint'];} 
else{ 
$n=''; 
$e=''; 
$m=''; 
$c='245'; 
} 
$mail->setFrom('[email protected]', 'Panasonic'); 
$mail->addAddress('[email protected]', 'Pragzz');  // Add a recipient 
//$mail->addAddress('[email protected]');    // Name is optional 
//$mail->addReplyTo('[email protected]', 'Information'); 
//$mail->addCC('[email protected]'); 
//$mail->addBCC('[email protected]'); 

//$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Complaint Number: '.$c; 
$mail->Body = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p><b>Message: </b>'.$m.'</p>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent. Your complaint will be attended within 48 hours. Your complaint No. is '.$c; 
} 
?> 
から https://pastebin.com/Rc3AGC8x

<html> 
<body bgcolor="#ccccb3"> 
<script type="text/javascript"> 
    function hello(min,max) { 
     var x; 
     x= Math.floor(Math.random()*(max-min+1)+min); 
     document.getElementById("complaint").value =x; 
     //document.write(x); 
    }; 
    </script> 
<center> 
<form action="http://localhost/PHPMailer-master/" method="post"> 
<p>Name:&nbsp;&nbsp;&nbsp;<input id="n" placeholder="Name" name="n" required></p> 
    <p>E-Mail: <input id="e" placeholder="Email Address" type="email" name="e" required></p> 
    <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea id="m" placeholder="write your message here" name="m" rows="10" required></textarea></p> 
    <p><input id="mybtn" type="submit" value="Submit Form" onClick="hello(112,78945)"></p> 
    <input type="hidden" value="The complaint id is : #" id="complaint" name="complaint"> 
    <!--<p>Clicks: <a id="clicks">0</a></p>--> 

</form> 
</center> 
</body> 
</html> 

ここでは、PHPコードです

パスワードとユーザー名フィールドが故意に削除されました。

HTMLスクリプトには、クレームがIDである隠しタイプのフォームフィールドが含まれています。

のjavascript関数から値を取得できず、PHPコードに送信します。

+0

コードには大きなセキュリティ上の欠陥があります。 SQLインジェクション – Rushikumar

+0

のボタンをクリックすると、フォームが送信されます。そのような状況では、ブラウザが他のスクリプト作成タスクを実行することを期待するべきではありません。とにかくこれの目的は何ですか?ランダムな値が必要な場合は、PHPで直接作成することもできます。 – CBroe

+1

@Rushikumar:SQLインジェクションの脆弱性はどこにありますか? – David

答えて

0

次のコードを試してください。私はJS部分を修正し、送信ボタンの前に隠されたfeildを配置しました。今はうまくいっています。

<html> 
<body bgcolor="#ccccb3"> 
<center> 
    <form action="http://localhost/PHPMailer-master/" method="post"> 
     <p>Name:<input id="n" placeholder="Name" name="n" required></p> 

     <p>E-Mail: <input id="e" placeholder="Email Address" type="email" name="e" required></p> 

     <p><textarea id="m" placeholder="write your message here" name="m" rows="10" required></textarea></p> 

     <input type="hidden" value="100" id="complaint" name="complaint"> 

     <p><input id="mybtn" type="submit" value="Submit Form" onClick="hello(112,78945)"></p> 

    </form> 
</center> 
<script type="text/javascript"> 
    function hello(min,max) { 
     var complaint = document.getElementById("complaint").value 
     console.log(complaint); 
    }; 
    </script> 
</body> 
</html>