提交表单时发送电子邮件

时间:2016-04-15 04:51:36

标签: php forms email

我正在使用Dreamweaver创建一个简单的即将推出的网站。但是,当我单击表单上的“提交”按钮时,它只会打开我的默认邮件应用程序并要求我发送电子邮件。然后我做了一个用于发送电子邮件的PHP。如果有人能看到它,我将不胜感激。如果你修复了php,你能不能给我整个版本,我对这些东西并不是很擅长并且不了解大部分内容。

<!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">
            <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">&copy;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="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'])){
    $to = "nicholas@fictionfilming.com";
    $from = $_POST['email'];
    $sender_name = $_POST['name'];
    $subject = $_POST['select'];
    $textarea = $_POST['textarea'];
    $body = $sender_name . " wrote the following:" . "\n\n" . $textarea;
    $subject = $subject;
    mail($to,$subject,$body);

    if(mail($to,$subject,$body)){
    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>

1 个答案:

答案 0 :(得分:1)

尼古拉斯,首先要证明两个文件都在同一个文件夹中。 2)文件必须在网站中,我的意思是托管在ISP的机器上,在公共IP下,并设置sendmail服务。 3)改变行

<强> <br><input name="Send" type="submit" id="Send" value="Send">

<强> <br><input name="submit" type="submit" id="submit" value="Send">