已经在论坛上搜索了这个问题,找到了解决方案,但还没有找到它。
我有一个引导程序表单中的联系表单,我使用复选框进行了自定义。联系表单起作用,只是复选框的值(访客记录的内容)不会在电子邮件中发送(或出现)。
到目前为止看起来像这样:
HTML :
<form name="sentMessage" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Ihr Name *" id="name" required data-validation-required-message="Bitte geben Sie Ihren Namen ein.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Ihre Email *" id="email" required data-validation-required-message="Bitte geben Sie Ihre E-Mail ein.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Ihre Telefonnummer (optional)" id="phone" >
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<textarea type="address" class="form-control" placeholder="Ihre Adresse (optional)" id="address"></textarea>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Ihre Sozialversicherungsnummer (optional)" id="socialnumber">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Ihre Nachricht (optional)" id="message"></textarea>
<p class="help-block text-danger"></p>
</div>
<p>Woher kamen Sie? (optional)</p>
<div class="checkbox-inline">
<label><input type="checkbox" name="source[]" value="Google"><p>Google</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="source[]" value="Facebook"><p>Facebook</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="source[]" value="Fernsehen"><p>Fernsehen</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="source[]" value="Papiermedien"><p>Papiermedien</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="source[]" value="MuendlicheEmpfehlung"><p>Mündliche Empfehlung</label>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">Nachricht senden</button>
</div>
</div>
</form>
PHP :
<?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'];
$address = $_POST['address'];
$socialnumber = $_POST['socialnumber'];
$source = $_POST['source'];
// Create the email and send the message
$to = 'myemailaddress@gmail.com';
$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\nAdresse:\n$address\n\nSocialnumber: $socialnumber\n\nKommt von: $source\n\n";
$headers = "From: noreply@daf-ausbildung.at\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;
?>
正如你所看到的,我在我的名字中输入了名字和字符串括号=&#34;来源[]&#34;在我的复选框中(因为我已经在stackoverflow上的其他线程中找到它)。
联系表单中的其他所有内容都有效,我通过电子邮件(名称,社交名称和所有其他常规字段)获取。
最后,复选框的值不会显示在我的电子邮件中。
任何人都知道为什么?非常感谢你的帮助!
答案 0 :(得分:0)
$_POST['source']
是array
,请先尝试将其打包
$source = implode(', ', $_POST['source']);