2016-12-13 18 views
3

私はhtmlでフォームを作成しましたが、PHPスクリプトはメールに送信しようとしましたが、動作しません。私が間違っている場所を確認してください。送信フォームのデータを送信者のメールアドレスに送信

私は送信ボタンをクリックするたびに、指定された電子メールに電子メールを送信するのではなく、PHPコードの表示を開始します。

HTML 
 
---- 
 

 

 
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Form</title> <!-- Include CSS file here --> 
 
<link href="css/form.css" rel="stylesheet"> 
 
</head> 
 
<body onload="myFunction()"> 
 

 
<h1> Form Request </h1> 
 

 
<form name="contactform" action="email.php" method="post"> 
 

 
    Name: <input type="text" name="full_name"><br \><br \> 
 
    Id: <input type="text" id="id"><br \><br \> 
 
    Email id: <input type="email" email="email"><br \><br \> 
 
    <a href="Form_IP.pdf" download>Download Blank Form </a> <br \><br \><br \> 
 
    Upload Filled Form<br \><br \> 
 
    
 
    <input type="file" id="myFile" multiple size="50" onchange="myFunction()"> 
 

 
<p id="resellerfile"></p> 
 
    
 
<script> 
 
function myFunction(){ 
 
    var x = document.getElementById("myFile"); 
 
    var txt = ""; 
 
    if ('files' in x) { 
 
     if (x.files.length == 0) { 
 
      txt = "Select one or more files."; 
 
     } else { 
 
      for (var i = 0; i < x.files.length; i++) { 
 
       txt += "<br><strong>" + (i+1) + ". file</strong><br>"; 
 
       var file = x.files[i]; 
 
       if ('name' in file) { 
 
        txt += "name: " + file.name + "<br>"; 
 
       } 
 
       if ('size' in file) { 
 
        txt += "size: " + file.size + " bytes <br>"; 
 
       } 
 
      } 
 
     } 
 
    } 
 
    else { 
 
     if (x.value == "") { 
 
      txt += "Select one or more files."; 
 
     } else { 
 
      txt += "The files property is not supported by your browser!"; 
 
      txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead. 
 
     } 
 
    } 
 
    document.getElementById("resellerfile").innerHTML = txt; 
 
} 
 
</script> 
 
<br \><br \> 
 

 
<input type="submit" value="Submit"> 
 

 

 

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

 
========================

<?php 
 
//if "email" variable is filled out, send email 
 
    if (isset($_REQUEST['email'])) { 
 
    
 
    //Email information 
 
    $admin_email = "[email protected]"; 
 
    $email = $_REQUEST['email']; 
 
    $subject = $_REQUEST['subject']; 
 
    $id = $_REQUEST['id']; 
 
    
 
    //send email 
 
    mail($admin_email, "$subject", $id, "From:" . $email); 
 
    
 
    //Email response 
 
    echo "Thank you for contacting us!"; 
 
    } 
 
    
 
    //if "email" variable is not filled out, display the form 
 
    else { 
 
?> 
 

 
<form method="post"> 
 
    Name: <input type="text" name="full_name"><br \><br \> 
 
    Id: <input type="text" id="id"><br \><br \> 
 
    Email id: <input type="email" email="email"><br \><br \> 
 
    <input type="submit" value="Submit" /> 
 
    </form> 
 
    
 
<?php 
 
    } 
 
?>

+0

もそのサーバーなしでPHPファイルを実行しようとしているので、 –

答えて

2

phpスクリプトをブラウザで直接実行できないため、php scriptsが処理されてサーバーで実行され、ブラウザにHTML応答が送信されるため、生のPHPが表示されています。

したがって、サーバー上でリモートまたはローカルにphpスクリプトをホストする必要があります。 システムでローカルにサーバーをセットアップする場合は、XAMPまたはWAMPをインストールしてください。

下記のリンクを参照してください。

http://www.homeandlearn.co.uk/php/php1p3.html

+0

はどうもありがとうございます!私はそれを試みます。 – Nickie

0

あなたはそれが応答していますかどうかを確認するためにXAMPPのhtdocsのフォルダを使用して、それを試してみましたか?

+0

いいえ、私は持っていない... – Nickie