我正在使用Dreamweaver创建一个网站,我的网站有一个表单,但是当我点击提交按钮时,它会打开我的Outlook应用程序,并提供我想要的信息。我只是想知道是否可以在不通过我的电子邮件客户端的情况下将电子邮件发送到我的帐户。这是我的代码......
BTW我正在使用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>
答案 0 :(得分:2)
您的代码存在一些问题。
首先,删除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']
替换为$textarea
,同时为POST数组分配它。
旁注:请参阅以上关于&#34;提交&#34;和&#34;发送&#34 ;;相应地修改下面的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未包含在原始问题中,则超出了问题的范围。< / p>
您不知道如何访问您的文件,因此如果您在托管网站上,那么我给您的工作应该是有用的。
如果是服务器问题,那么这也超出了问题的范围,您需要联系您的服务提供商以获得技术支持。
如果您在自己的电脑上使用此功能,则需要安装PHP,网络服务器和mail()
,并正确配置并使用http://localhost/file.xxx
而不是file:///file.xxx
。
旁注:如果<option>
没有传递任何内容,那么您可能需要给它们值。
即:<option value="HELP / SUPPORT">
为其他人做这件事。
我相信我已经足够让你在这里继续前进。
答案 1 :(得分:0)
因为在表单标签中你提到了action为action =“mailto:mail@fictonfilming.com”,所以它试图访问outlook
将操作更改为php文件的名称 行动= “yourphpfilename.php”
答案 2 :(得分:0)
根据您的服务器配置,您可能无法使用简单的php邮件功能发送邮件。
要测试它,请使用:
print mail($to,$subject,$message,$headers);
如果结果不是1,那么事情就不好了,修复它可能并不容易。
我建议您使用基于PHPmailer或API的服务,例如MailGun。