将联系表单链接到电子邮件HTML / PHP

时间:2016-11-02 11:06:27

标签: php html contact-form

我正在尝试联系我们表单,

P.S。我不是开发人员,我的编码技巧非常有限。

这是HTML代码:(来自带有一些调整的模板)

<!--Contact Starts -->
<div class="container contactform center">
<h2 class="text-center  wowload fadeInUp">Get in touch</h2>
  <div class="row wowload fadeInLeftBig">
      <div class="col-sm-6 col-sm-offset-3 col-xs-12">
        <input type="text" placeholder="Name">
        <input type="text" placeholder="Company">
        <input type="text" placeholder="Email">
        <input type="text" placeholder="Subject">
        <textarea rows="5" placeholder="Message"></textarea>
        <button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>

      </div>
  </div>

这是PHP脚本:(自己写的)

$name = $_POST['Name'] ;
$from = $_POST['Email'] ;
$message = $_POST['Message'] ;
$to = "contact@mywebsite.com" ;
$subject = "Website Contact Form" ;

mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
echo "Your Message Has Been Sent" ;

我不确定我做错了什么,但这不符合工作原理。

位于/assets/php/emailscript.php的名为emailscript.php的php文件

现在我收到错误此错误:“未找到

在此服务器上找不到请求的文档。“

3 个答案:

答案 0 :(得分:1)

尝试这个......

<!--Contact Starts -->
<div class="container contactform center">
<h2 class="text-center  wowload fadeInUp">Get in touch</h2>
  <div class="row wowload fadeInLeftBig">
      <div class="col-sm-6 col-sm-offset-3 col-xs-12">
        <form action="/assets/php/emailscript.php" method="post">
          <input type="text" placeholder="Name" name="Name">
          <input type="text" placeholder="Company" name="Company">
          <input type="text" placeholder="Email" name="Email">
          <input type="text" placeholder="Subject" name="Subject">
          <textarea rows="5" placeholder="Message" name="Message"></textarea>
          <button type="submit" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
        </form>

      </div>
  </div>

答案 1 :(得分:0)

请将表单元素放在<form>标记中。并给每个元素一个名称属性。通过使用name属性,我们将在php中获取表单数据。

 <form name="contact" action="/assets/php/emailscript.php" method="POST">
 <input type="text" placeholder="Name" name="contact_name">
 <input type="text" placeholder="Company" name="company">
 <input type="text" placeholder="Email" name="email">
 <input type="text" placeholder="Subject" name="subject"> 
 <textarea rows="5" placeholder="Message" name="message"></textarea>
 <button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button> 
</form>

答案 2 :(得分:-2)

在isset函数中包围您的代码以避免任何错误

<?php
if(isset($_POST['Name']))
{

    $name=$_POST['Name'] ;
    $from=$_POST['Email'] ;
    $message=$_POST['Message'] ;
    $to="contact@mywebsite.com" ;
    $subject="Website Contact Form" ;

    mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
    // it echo not eco
    echo "Your Message Has Been Sent" ;

}
?>