遇到PHP电子邮件表单问题

时间:2014-10-03 01:26:15

标签: php html forms twitter-bootstrap-3

我是PHP的新手,我正在尝试制作一个基本的联系表单。我创建了表单,就我所知,PHP看起来正确。但是,电子邮件似乎没有发送。

通过单击顶部附近的“联系模式测试”按钮,可以在此处http://abenjamin765.github.io/pushpin2/看到该表单。

我错过了什么吗?

HTML:

<div class="modal fade" id="contact">
  <div class="modal-dialog">
    <div class="modal-content">
      <form class="form-horizontal" name="contactform" method="post" action="php/contact.php" role="form">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">Get a Quote</h4>
      </div>
      <div class="modal-body">

        <div class="form-group">
          <label for="contact-name" class="col-sm-2 control-label">Name</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="contact-name" placeholder="First and Last name">
          </div>
        </div>

        <div class="form-group">
          <label for="contact-email" class="col-sm-2 control-label">Email</label>
          <div class="col-sm-10">
            <input type="email" class="form-control" id="contact-email" placeholder="example@domain.com">
          </div>
        </div>

        <div class="form-group">
          <label for="contact-message" class="col-sm-2 control-label">Message</label>
          <div class="col-sm-10">
            <textarea type="text" rows="4" class="form-control" id="contact-message" placeholder="Write a message..."></textarea>
          </div>
        </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Send</button>
      </div>
      </form>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

这是我的php ...

<?php
/* Set e-mail recipient */
$myemail = "hello@pushpinevents.com";

/* Check all form inputs using check_input function */
$name = check_input($_POST['contact-name'], "Your Name");
$email = check_input($_POST['contact-email'], "Your E-mail Address");
$message = check_input($_POST['contact-message'], "Your Message");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */

$subject = "New lead from $name!";

$message = "

Someone has sent you a message using your contac form:

Name: $name
Email: $email

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thankyou.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Please try again</p>

</body>
</html>
<?php
exit();
}
?>

1 个答案:

答案 0 :(得分:0)

尝试将ID更改为名称或添加与您的ID同名的名称字段。

相关问题