无法从表单提交中获取信息

时间:2016-06-11 18:34:34

标签: php html5 forms

我创建了表单,并希望在用户提交请求时将邮件发送到我的邮箱。我发现了一个PHP脚本,它可以适应我的表单并且可以正常使用其他表单,但是当我尝试将该脚本用于我的表单时,它不能按预期工作。 这是我在html中的表单 -

 <form action="contact.php" method="post" name="form1">
                            <div class="form-group">
                                <input type="text" class="form-control" id="Name" placeholder="Name*" name="name">
                            </div>
                            <div class="form-group">
                                <input type="phone" class="form-control" id="Phone" placeholder="Phone*" name="phone">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control" id="Address" placeholder="Full Address*" name="address">
                            </div>
                            <div class="form-group">
                                <textarea class="form-control" rows="3" placeholder="Order - List Outlets and Meals*" name="order"></textarea>
                            </div>
                            <div class="form-group">
                                <label><input style="vertical-align: center;"type="checkbox" /> Accept  the <a class="" data-toggle="modal" data-target="#myModal">Terms & Conditions</a>
                                </label>
                            </div>
                            <a href="contact.php" class="btn-block">ORDER!</a>
                        </form>

这是我的php脚本 - here

1 个答案:

答案 0 :(得分:1)

确保php脚本与表单

位于同一目录中
<form action="contact.php" method="post" name="form1">
  <!--content-->
  <input type="submit" value="ok" />
</form>

使用phpmailer https://github.com/PHPMailer/PHPMailer发送邮件,

require_once('class.phpmailer.php');

require_once("PHPMailerAutoload.php");

$mail->IsSMTP(); // telling the class to use SMTP

$mail->SMTPAuth   = true;                  // enable SMTP authentication

$mail->SMTPSecure = "tls";                 // sets the prefix to the servier

$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server

$mail->Port       = 587;                   // set the SMTP port for the 

$mail->Username   = "yourusername@gmail.com";  // GMAIL username

$mail->Password   = "yourpassword";            // GMAIL password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible";

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {

  echo "Mailer Error: " . $mail->ErrorInfo;

} else {

  echo "Message sent!";

}