重新发布代码:无法通过电子邮件获取表单数据

时间:2014-05-23 01:53:04

标签: php html forms

问题:我无法在用户的电子邮件中获取用户提交的表单数据。当用户点击提交时,表单会刷新,但不会向我发送任何电子邮件。如果有人在这里发现任何错误。我非常感谢你提前。

HTML CODE:

<div class="content">
      <h1>Contact Us</h1>
      <form role="form">
        <div class="form-group">
            <form action="email.php" method="post">
          <input type="text" class="form-control" name="name" id="exampleInputName" placeholder="Your good name" required>
          <label for="exampleInputName"><i class="icon-tag"></i></label>
          <div class="clearfix"></div>
        </div>
        <div class="form-group">
          <input type="email" class="form-control" name="email" id="exampleInputEmail1" placeholder="Enter your email address" required>
          <label for="exampleInputEmail1"><i class="icon-inbox"></i></label>
          <div class="clearfix"></div>
        </div>
        <div class="form-group textarea">
          <textarea rows="6" class="form-control" name="message" id="exampleInputMessage" placeholder="How can we help your business" required></textarea>
          <label for="exampleInputMessage"><i class="icon-pencil"></i></label>
          <div class="clearfix"></div>
        </div>
        <input type="submit" name="submit" class="btn btn-large" value="Send Message">   </button>
      </form>

    </div>
  </div>

在这里输入代码

PHP代码:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo'; 
$to = 'danish@cloudtechteam.com'; 
$subject = 'Hello';


$body = "From: $name\n E-Mail: $email\n Message:\n $message";

$host = "mail.cloudtechteam.com";
$port = "25";
$smtp = Mail::factory('smtp',
 array ('host' => $host,
 'port' => $port,));
  $mail = $smtp->send($to, $headers, $body);

if ($_POST['submit']) {              
    if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
?>

1 个答案:

答案 0 :(得分:0)

您的表单使用的是get方法,<form>的默认值。将表单更改为

<form role="form" method="post">