【问题标题】:How to send Bootstrap Radio buttons results to a email using PHP如何使用 PHP 将 Bootstrap 单选按钮结果发送到电子邮件
【发布时间】:2014-11-14 21:36:57
【问题描述】:

您好,我有一个在引导程序中制作的单选按钮表单,我想知道服务器端代码需要是什么才能向我的电子邮件发送带有表单结果的电子邮件。

我希望用户填写表单(单选按钮)然后点击提交,

当他点击提交时,必须打开一个新窗口,上面写着例如“谢谢,请在下面输入电子邮件以获取结果”

然后必须有一个我要广告的字段,要求提供电子邮件,然后是获取结果按钮。

我想将单选按钮的结果与他们提交的邮件中的相应答案(选择)一起发送到我的电子邮件。

例如这样接收它:

发件人:输入的电子邮件

日期:

收件人:我的电子邮件

主题:调查结果

问题 1 是的

问题 2 否

等 等等

这是我用于 HTML 端的代码:

<div class="container">
<form class="form-horizontal action="contactmail.php" method="post" id="form">
<fieldset>

<!-- Form Name -->
<legend><b style="color:red">Quick Survey</b></legend>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Were you injured in a car or taxi accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 1" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 1" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Was it within the past 3 years?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 2" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 2" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Did you have serious injuries?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 3" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 3" id="radios-1" value="no">
      no
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Were you in hospital because of the accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 4" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 4" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">How many days did you spend in hospital?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 5" id="radios-0" value="1 Day">
      1 Day
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 5" id="radios-1" value="1-7 Days">
      1-7 Days
    </label>
    <label class="radio" for="radios-2">
      <input type="radio" name="Question 5" id="radios-2" value="7-14 Days">
      7-14 Days
    </label>
    <label class="radio" for="radios-3">
      <input type="radio" name="Question 5" id="radios-3" value="14-21 Days">
      14-21 Days
    </label>
    <label class="radio" for="radios-4">
      <input type="radio" name="Question 5" id="radios-4" value="21-28 Days">
      21-28 Days
    </label>
    <label class="radio" for="radios-5">
      <input type="radio" name="Question 5" id="radios-5" value="1 Month or more">
      1 Month or more
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Did you undergo surgery?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 6" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 6" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Multiple Radios -->
<div class="control-group">
  <label class="control-label" for="radios">Do you still suffer as a result of the accident?</label>
  <div class="controls">
    <label class="radio" for="radios-0">
      <input type="radio" name="Question 7" id="radios-0" value="Yes">
      Yes
    </label>
    <label class="radio" for="radios-1">
      <input type="radio" name="Question 7" id="radios-1" value="No">
      No
    </label>
  </div>
</div>

<!-- Button -->
<div class="control-group">
  <label class="control-label" for="Submit"></label>
  <div class="controls">
    <button id="Submit" name="Submit" class="btn btn-info">Submit</button>
  </div>
</div>

</fieldset>
</form>


</div>

感谢所有帮助

编辑:它现在可以工作了,这是我使用的代码(记住不需要修剪)

<?php
/**
    if(isset($_POST['submit'])) {
        if (empty($_POST['email']) || empty($_POST['Question1']) || empty($_POST['Question2']) || empty($_POST['Question3']) || empty($_POST['Question4']) || empty($_POST['Question5']) || empty($_POST['Question6']) || empty($_POST['Question7'])) {
            $error = true;
        } 
        else {
**/         $email = trim($_POST['email']);
            $to = "Enteryourmail@domain.co.za,$email";

            $Question1 = trim($_POST['Question1']);
            $Question2 = trim($_POST['Question2']);
            $Question3 = trim($_POST['Question3']);
            $Question4 = trim($_POST['Question4']);
            $Question5 = trim($_POST['Question5']);
            $Question6 = trim($_POST['Question6']);
            $Question7 = trim($_POST['Question7']);
            $email = trim($_POST['email']);
            $phone = trim($_POST['phone']);
            $frommail = "info@mydomain.co.za";

            $subject = "Contact Form";

            $message =  "Were you injured in a car or taxi accident?: $Question1 \r\n Was it within the past 3 years?: $Question2 \r\n Did you have serious injuries?: $Question3 \r\n Were you in hospital because of the accident?: $Question4 \r\n How many days did you spend in hospital?: $Question5 \r\n Did you undergo surgery?: $Question6 \r\n Do you still suffer as a result of the accident?: $Question7 \r\n Email: $email \r\n Phone: $phone";
            $headers = "From:" . $frommail;
            $mailsent = mail($to, $subject, $message, $headers);

/**
       }
  } **/
?>

【问题讨论】:

    标签: php jquery twitter-bootstrap-3 radio-button sendmail


    【解决方案1】:

    到目前为止,您只有 HTML。

    接下来你需要学习的东西:

    学习起来非常简单。然后,如果您在阅读后有任何疑问,请返回您的问题。

    【讨论】:

    • 我非常感谢您的帮助,我想到目前为止我只收到了一个问题。我在本节看到Radio Buttons with PHP Form Handling。他们说我需要收音机值:
    • 您需要做的第一件事是为您的表单创建一个操作,这样您就可以将表单中的数据发送到脚本(第一个链接)。然后,您需要从单选按钮(第二个链接)和其他输入中获取值,并根据需要发送电子邮件(第三个链接)。
    • 我明白了,但是看看这个例子:简单!只需为您的单选按钮添加一个值。 'Email Phone' 因为我的值将始终是 Yes 或 No,我不知道如何才能使 7 个单选按钮具有唯一性。对不起,菜鸟问题,我还没有真正接触过php。 (真的很想找时间学习)
    • 嗯,你最初的问题不是关于它,但应该唯一的不是属性值,而是属性名称id。如果答案对您最初的问题有帮助,请记得点赞。
    • 我知道我最初的问题并不是专门针对那个问题,但是在您提供的链接之后,我想到了这个问题并构成原始问题的一部分,基本上代码必须是什么才能实现原始问题问题。同样,我如何使这些唯一,因为每个问题的 ID 和名称都是相同的......
    猜你喜欢
    • 2018-02-05
    • 2017-12-12
    • 2013-02-19
    • 2013-04-17
    • 2012-10-01
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多