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

时间:2015-02-26 01:29:56

标签: php html css

用一段代码一直非常令人沮丧。除了选择器代码外,一切都很棒!它不会发布到电子邮件,只显示空白! 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.\n\n"."Here are the details:\n\nName: $name\n\nEmail:       $email_address\n\nPhone: $phone\n\nMessage:\n$message\n\nCamp: $country";
$headers = "From: noreply@yourdomain.com\n"; // 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;    

以下是输出示例:enter image description here

1 个答案:

答案 0 :(得分:0)

您是否需要在选项中使用value属性才能将值传递给php?例如:

<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>
相关问题