Html 表单,提交后直接发送到邮箱
Html Form, when submitted, send straight to email
我正在使用 Dreamweaver 创建一个网站,我的网站有一个表单,但是当我单击提交按钮时,它会打开我的 outlook 应用程序,其中包含我想要的信息。我只是想知道是否可以在不通过我的电子邮件客户端的情况下将电子邮件发送到我的帐户。这是我的代码...
顺便说一句,我正在使用 Dreamweaver 编辑所有代码。
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fiction Filming</title>
<link rel="shortcut icon" href="images/favicon3.ico" type="image/x-icon" />
<style type="text/css">
body {
background-color: #2c2c2c;
}
</style>
<link href="Css/singlePageTemplate.css" rel="stylesheet" type="text/css">
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n2:default.js" type="text/javascript"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Navigation -->
<!-- Hero Section -->
<!-- About Section -->
<!-- Stats Gallery Section -->
<div class="gallery"><img src="Images/Newbannercomingsoon.png" alt="" width="1000" height="500" class="logo-pic"/> </div>
<!-- Parallax Section -->
<!-- More Info Section -->
<!-- Footer Section -->
<section class="footer_banner" id="contact">
<form class="subscribeForm form-fix" name="Subscription Form" method="post" action="mailform.php" enctype="text/plain">
<div class="newform">
<div> </div>
<div>
<input id="fname" type="text" placeholder="NAME" name="name" required>
</div>
<div>
<input name="email" type="email" required id="email" placeholder="EMAIL">
</div>
<div>
<select name="select" required id="myselect">
<option>HELP / SUPPORT</option>
<option>BUSINESS ENQUIRES</option>
<option>OTHER</option>
</select>
</div>
<div class="text-form">
<div>
<textarea name="textarea" required id="textarea" placeholder="TYPE YOUR TEXT HERE"></textarea>
</div>
</div>
<br><input name="Send" type="submit" id="Send" value="Send">
</div>
</form>
<!-- Step 1: Add an email field here -->
<!-- Step 2: Add an address field here -->
<!-- Step 3: add a submit button here -->
</section>
<!-- Copyrights Section -->
<div class="copyright">©2016 - <strong>Fiction filming</strong></div>
</div>
<!-- Main Container Ends -->
</body>
</html>
此外,这是我的 php 文件...如果您能修复它,那将非常有帮助。
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$to = "example@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$sender_name = $_POST['name'];
$select = $_POST['select'];
$message = $sender_name . " wrote the following:" . "\n\n" . $_POST['textarea'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
</body>
</html>
这是新的 PHP
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="3;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$to = "mail@fictionfilming.com";
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
}
}
// $headers = "From:" . $from;
// $headers2 = "From:" . $to;
//echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
//}
?>
</body>
</html>
因为你在表单标签中提到了作为 action="mailto:mail@fictonfilming.com" 的操作,它正在尝试访问 outlook
将操作更改为您的 php 文件的名称
动作="yourphpfilename.php"
根据您的服务器配置,您可能无法使用简单的 php 邮件功能发送邮件。
要测试它,请使用:
print mail($to,$subject,$message,$headers);
如果结果不是 1,说明有些东西不好,修复它可能并不容易。
我建议您使用 PHPmailer 或基于 API 的服务,例如 MailGun。
您的代码存在一些问题。
首先,移除enctype="text/plain"
。该类型无法发送带有表单的 POST 数组。
您还应该删除 <META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
,因为这可能会对您造成一些恶作剧。
那么您的输入 <input name="Send" type="submit" id="Send" value="Send">
具有 Send
名称属性,并且您正在使用以下永远不会启动的条件语句:
if(isset($_POST['submit']))
要么将输入重命名为 name="submit"
,要么将条件语句重命名为 if(isset($_POST['Send']))
; 选择权在你。
错误报告可能会让您大吃一惊。
现在,我不明白为什么你的代码中有这个 $headers2 = "From:" . $to;
因为它没有在任何地方使用,所以我不能说太多,除了摆脱它。
如果有人决定不填写任何或所有输入,导致电子邮件为空,您还应该检查是否有空字段。
即,我在为 POST 数组分配它时用 $textarea
替换了你的 $_POST['textarea']
。
旁注:参见上面关于 "submit" 和 "Send" 的内容;在此处对下面的 if(isset($_POST['submit']))
进行相应修改。
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
// Put your other mail code here
}
}
所有这些假设 mail()
在您 运行 来自的服务器上可用。
我建议你更换:
mail($to,$subject,$message,$headers);
带有条件语句,以检查是否已发送:
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
旁注:显示错误只应在暂存阶段进行,绝不能在生产阶段进行。
脚注:
我注意到您使用的是 ID,因此如果您使用的 JS/Ajax/jQuery 没有包含在您的原始问题中,则超出了问题的范围。
不知道您是如何访问您的文件的,所以如果您在托管站点上,那么我给您的应该可以工作。
如果是服务器问题,那也不在问题范围内,您需要联系您的服务提供商以获得技术支持。
如果您在自己的 PC 上使用它,则 PHP、网络服务器和 mail()
需要安装、正确配置并使用 http://localhost/file.xxx
而不是 file:///file.xxx
.
旁注:如果 <option>
没有传递任何内容,那么您可能必须给它们赋值。
即:<option value="HELP / SUPPORT">
同时为其他人做这件事。
我相信我已经给了你足够的东西让你继续前进。
我正在使用 Dreamweaver 创建一个网站,我的网站有一个表单,但是当我单击提交按钮时,它会打开我的 outlook 应用程序,其中包含我想要的信息。我只是想知道是否可以在不通过我的电子邮件客户端的情况下将电子邮件发送到我的帐户。这是我的代码...
顺便说一句,我正在使用 Dreamweaver 编辑所有代码。
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fiction Filming</title>
<link rel="shortcut icon" href="images/favicon3.ico" type="image/x-icon" />
<style type="text/css">
body {
background-color: #2c2c2c;
}
</style>
<link href="Css/singlePageTemplate.css" rel="stylesheet" type="text/css">
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n2:default.js" type="text/javascript"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Navigation -->
<!-- Hero Section -->
<!-- About Section -->
<!-- Stats Gallery Section -->
<div class="gallery"><img src="Images/Newbannercomingsoon.png" alt="" width="1000" height="500" class="logo-pic"/> </div>
<!-- Parallax Section -->
<!-- More Info Section -->
<!-- Footer Section -->
<section class="footer_banner" id="contact">
<form class="subscribeForm form-fix" name="Subscription Form" method="post" action="mailform.php" enctype="text/plain">
<div class="newform">
<div> </div>
<div>
<input id="fname" type="text" placeholder="NAME" name="name" required>
</div>
<div>
<input name="email" type="email" required id="email" placeholder="EMAIL">
</div>
<div>
<select name="select" required id="myselect">
<option>HELP / SUPPORT</option>
<option>BUSINESS ENQUIRES</option>
<option>OTHER</option>
</select>
</div>
<div class="text-form">
<div>
<textarea name="textarea" required id="textarea" placeholder="TYPE YOUR TEXT HERE"></textarea>
</div>
</div>
<br><input name="Send" type="submit" id="Send" value="Send">
</div>
</form>
<!-- Step 1: Add an email field here -->
<!-- Step 2: Add an address field here -->
<!-- Step 3: add a submit button here -->
</section>
<!-- Copyrights Section -->
<div class="copyright">©2016 - <strong>Fiction filming</strong></div>
</div>
<!-- Main Container Ends -->
</body>
</html>
此外,这是我的 php 文件...如果您能修复它,那将非常有帮助。
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$to = "example@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$sender_name = $_POST['name'];
$select = $_POST['select'];
$message = $sender_name . " wrote the following:" . "\n\n" . $_POST['textarea'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
</body>
</html>
这是新的 PHP
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="3;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$to = "mail@fictionfilming.com";
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
}
}
// $headers = "From:" . $from;
// $headers2 = "From:" . $to;
//echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
//}
?>
</body>
</html>
因为你在表单标签中提到了作为 action="mailto:mail@fictonfilming.com" 的操作,它正在尝试访问 outlook
将操作更改为您的 php 文件的名称 动作="yourphpfilename.php"
根据您的服务器配置,您可能无法使用简单的 php 邮件功能发送邮件。
要测试它,请使用:
print mail($to,$subject,$message,$headers);
如果结果不是 1,说明有些东西不好,修复它可能并不容易。
我建议您使用 PHPmailer 或基于 API 的服务,例如 MailGun。
您的代码存在一些问题。
首先,移除enctype="text/plain"
。该类型无法发送带有表单的 POST 数组。
您还应该删除 <META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
,因为这可能会对您造成一些恶作剧。
那么您的输入 <input name="Send" type="submit" id="Send" value="Send">
具有 Send
名称属性,并且您正在使用以下永远不会启动的条件语句:
if(isset($_POST['submit']))
要么将输入重命名为 name="submit"
,要么将条件语句重命名为 if(isset($_POST['Send']))
; 选择权在你。
错误报告可能会让您大吃一惊。
现在,我不明白为什么你的代码中有这个 $headers2 = "From:" . $to;
因为它没有在任何地方使用,所以我不能说太多,除了摆脱它。
如果有人决定不填写任何或所有输入,导致电子邮件为空,您还应该检查是否有空字段。
即,我在为 POST 数组分配它时用 $textarea
替换了你的 $_POST['textarea']
。
旁注:参见上面关于 "submit" 和 "Send" 的内容;在此处对下面的 if(isset($_POST['submit']))
进行相应修改。
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
// Put your other mail code here
}
}
所有这些假设 mail()
在您 运行 来自的服务器上可用。
我建议你更换:
mail($to,$subject,$message,$headers);
带有条件语句,以检查是否已发送:
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
旁注:显示错误只应在暂存阶段进行,绝不能在生产阶段进行。
脚注:
我注意到您使用的是 ID,因此如果您使用的 JS/Ajax/jQuery 没有包含在您的原始问题中,则超出了问题的范围。
不知道您是如何访问您的文件的,所以如果您在托管站点上,那么我给您的应该可以工作。
如果是服务器问题,那也不在问题范围内,您需要联系您的服务提供商以获得技术支持。
如果您在自己的 PC 上使用它,则 PHP、网络服务器和 mail()
需要安装、正确配置并使用 http://localhost/file.xxx
而不是 file:///file.xxx
.
旁注:如果 <option>
没有传递任何内容,那么您可能必须给它们赋值。
即:<option value="HELP / SUPPORT">
同时为其他人做这件事。
我相信我已经给了你足够的东西让你继续前进。