douxuelv7755 2015-11-25 02:26
浏览 60
已采纳

缺少电子邮件中的表单字段

I have made a web form that sends an email with the form information contained within. I have a couple of issues I haven't been able to fix though, and I am hoping someone can help.

  1. The selection boxes for Current Club Membership do not return any information in the email, just a blank space where the information should be, even though an option is selected.
  2. After the form is sent the mail.php file loads. I would like a thank you HTML page to load instead. How do I do that? I tried changing the action attribute in the HTML to the page I want, but then the email doesn't send.

The HTML:

<form method="post" action="mail.php">
<div class="row uniform">

<div class="6u 12u$(xsmall)">
<label for="name">Full Name</label>
<input name="name" type="text" class="required" id="name" value="" />
</div>


<div class="6u$ 12u$(xsmall)">
<label for="email">Email Address</label>
<input name="email" type="email" class="required" id="email" value="" />
</div>


<div class="6u 12u$(xsmall)">
<label for="date">Date of Birth</label>
<input name="date" type="text" class="required" id="date" value="" />
</div>


<div class="6u$ 12u$(xsmall)">
<label for="age">Age as of July 1, 2016</label>
<input name="age" type="text" class="required" id="age" value="" />
</div>

<div class="6u 12u$(xsmall)">
<label for="phone">Phone Number</label>
<input name="phone" type="tel" class="required" id="phone" value="" />
</div>

<div class="12u$">
<label for="club">Current Club Membership</label>
<div class="select-wrapper">
<select name="club" class="required" id="club">
<option value="">-</option>
<option value="Colonial Road Runners">Colonial Road Runners</option>
<option value="Peninsula Track Club">Peninsula Track Club</option>
<option value="Tidewater Striders">Tidewater Striders</option>
</select>
</div>
</div>


<div class="12u$">
<label for="message">Message</label>
<textarea name="message" id="message" rows="6"></textarea>
</div>

<div class="12u$">
<ul class="actions">
<li><input type="submit" name="submit" value="Send Message" class="special" /></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>

The php:

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $date = $_POST['date'];
        $age = $_POST['age'];
        $phone = $_POST['phone'];
        $message = $_POST['message'];
        $from = 'From: hrsupergp@gmail.com'; 
        $to = '6linewrasse@gmail.com'; 
        $subject = 'New Registration';

        $body.='email: '. $_POST['email']."
";
        $body.='date: '. $_POST['date']."
";
        $body.='age: '. $_POST['age']."
";
        $body.='phone: '. $_POST['phone']."
";
        $body.='club: '. $_POST['club']."
";
        $body = "From: $name
                 E-Mail: $email
                 Date: $date
                 Age 7/2016: $age
                 Phone:  $phone
                 Club:  $club
                 Message: $message";
        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }


    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
?>
  • 写回答

2条回答 默认 最新

  • drlhsfqoa350437979 2015-11-25 02:36
    关注

    You need to include at the select tagonchange="document.getElementById('text_content').value=this.options[this.selectedIndex].text"

    And this input is used to store the value from the option

    <input type="hidden" name="test_text" id="text_content" value="" />
    

    get the text of the selected option using php

    To redirect,

       header("Location: thankyou.html");
       die();
    

    after the if statement where you return the string of you will be in touch. How to make a redirect in PHP?

    You can pass the string to another page via URL. Just create a <div class="thankyou"> on the new page and the URL be something like thankyou.html?thankyou=thank%20you%20very%20much. So your header will look something like this:

    header("Location: thankyou.html?thankyou=thank%20you%20very%20much");
           die();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)