简体   繁体   English

将html表单数据发送到发件人的电子邮件

[英]Sending html Form data to sender's email

I have created a form in html and with the php script trying to send it to the email however it's not working. 我已经在html中创建了一个表单,并且php脚本试图将其发送到电子邮件但是它无法正常工作。 Can you please check where I'm wrong? 你能检查我错在哪里吗?

Whenever I click on send button, it starts showing the php code instead of sending the email to the given email. 每当我点击发送按钮,它就会开始显示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 = "xyx@submit.com"; $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 } ?> 

It is showing you raw php because php scripts can not be executed directly by the browser, php scripts are processed and executed by server and then html response is sent to the browser. 它显示你原始的PHP因为php脚本不能直接由浏览器执行, php scripts由服务器处理和执行,然后html响应被发送到浏览器。

So, you need to host the php script on a server remotely or locally. 因此,您需要远程或本地在服务器上托管php脚本。 if you want to set up a server locally on your system try installing XAMP or WAMP. 如果要在系统上本地设置服务器,请尝试安装XAMP或WAMP。

Refer to the link below. 请参阅以下链接。

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

您是否尝试过使用Xampp的htdocs文件夹来查看它是否正在响应?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM