doxd96148 2015-02-26 01:29
浏览 34

通过PHP发送选择表格到电子邮件

been having a really frustrating rough time with a piece of code. Everything is working fantastic EXCEPT for the selector code! It won't post to the email and just shows up blank! http://brandoncamerer.com/africa/later.php

HTML:

<input type="email" class="form-control" placeholder="Your Email *" id="email" required="" data-validation-required-message="Please enter your email address.">

<input type="text" class="form-control" placeholder="Your Phone *" id="phone" required="" data-validation-required-message="Please enter your phone number.">

<textarea class="form-control" placeholder="Your Message *" id="message"     required="" data-validation-required-message="Please enter a message."></textarea>

<select name="country" style="width:100%;" class="selectpicker">
<option>Choose a camp for me</option>  
<optgroup label="Cote D'Ivoire">
<option>Cote D'Ivoire Camps - Mar 27-29</option>  
</optgroup>
</select>

PHP:

if(empty($_POST['name'])        ||
empty($_POST['email'])      ||
empty($_POST['phone'])      ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$country = $_POST['country'];

// Create the email and send the message
$to = 'brandon.camerer@gmail.com'; // Add your email address inbetween the ''     replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact     form.

"."Here are the details:

Name: $name

Email:       $email_address

Phone: $phone

Message:
$message

Camp: $country";
$headers = "From: noreply@yourdomain.com
"; // This is the email address the     generated message will be from. We recommend using something like  noreply@yourdomain.com.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;    

Here is an example of the output: enter image description here

  • 写回答

1条回答 默认 最新

  • dongping9475 2015-02-26 01:50
    关注

    Don't you need to have a value attribute in your options to be able to pass the value to php? For example:

    <select name="country" style="width:100%;" class="selectpicker">
        <option value="choose">Choose a camp for me</option>  
        <optgroup label="Cote D'Ivoire">
            <option value="cote-divoire'>Cote D'Ivoire Camps - Mar 27-29</option>  
        </optgroup>
    </select>
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP