我无法将此PHP表单捕获并转发到电子邮件

时间:2014-06-10 16:58:29

标签: php forms email

该表单适用于慈善活动网站,我真的很难让PHP从表单中获取信息并将其发送到我们需要的电子邮件中。我不是一个网页设计师(这是在引导程序中),但我认为问题出在PHP中。谢谢您的帮助!

    <div class="panel-body">
    <form name="contactform" method="post">
      <div class="form-group">
        <label for="name">Full Name</label>
        <div class="col-lg-8">
          <input type="text" class="form-control" id="name" name="name" placeholder="Full Name">
        </div>
      </div>
      <div class="form-group">
        <label for="phone">Phone Number</label>
        <div class="col-lg-8">
          <input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone Number">
        </div>
      </div>
      <div class="form-group">
        <label for="email">Email Address</label>
        <div class="col-lg-8">
          <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
        </div>
      </div>
      <div class="form-group">
        <label for="shift">Preferred Shift</label>
        <div class="col-lg-8">
          <select class="form-control" id="shift" name="shift">
            <option value="1" required> Shift 1: 12pm - 3:30pm </option>
            <option value="2" required> Shift 2: 3:30pm - 7pm </option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="shirt">Shirt Size</label>
        <div class="col-lg-8">
          <select class="form-control" id="shirt" name="shirt">
            <option value="1" required> XS </option>
            <option value="2" required> S </option>
            <option value="3" required> M </option>
            <option value="4" required> L </option>
            <option value="5" required> XL </option>
            <option value="6" required> XXL </option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="comments">Comments </label>
        <div class="col-lg-8">
          <textarea class="form-control" type="text" id="comments" name="comments" placeholder="Comments Not Required"></textarea>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-4 col-lg-6">
          <button type="submit" class="btn btn-success" type="submit" value="submit"> Submit </button>
          <br>
          <h5> *all volunteers must be 18 years or older </h5>
        </div>
      </div>
    </form>
  </div>

我将PHP包含在同一个站点中。它看起来像这样:

<?php 
if(isset($_POST['submit'])){
    $to = "info@charitycelebration.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $shift = $_POST['shift'];
    $shirt = $_POST['shirt'];
    $comments = $_POST['comments'];
    $subject = "CC volunteer submission";

    $message .= "Name: ".clean_string($name)."\n";

    $message .= "Phone: ".clean_string($phone)."\n";

    $message .= "Email: ".clean_string($from)."\n";

    $message .= "Shift: ".clean_string($shift)."\n";

    $message .= "Shirt: ".clean_string($shirt)."\n";

    $message .= "Comments: ".clean_string($comments)."\n";


    mail($to,$subject,$message);
    echo "==[]-]0ploi9ok.,/,Thank you " . $name . ", we will see you soon!";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

2 个答案:

答案 0 :(得分:1)

mail()高度依赖于在服务器上正确设置邮件。就个人而言,我喜欢PEAR Mail_mime软件包的额外控制,但如果您可以启动并运行基本邮件功能,这对您的使用来说太过分了

专注于首先发送基本邮件 - 没有变量或其他元素,然后一旦成功返回并插入表单元素。

答案 1 :(得分:0)

尝试echo变量$to, $subject, $message而不是调用mail(),以查看表格中mail()的所有输入是否正确,clean_string()你使用的功能。如果mail()的输入正确,则mail()可能存在问题。