这是我的HTML:
<form action="expertform.php" method="post">
<input type="hidden" name="eaid" value="" class="hidden">
<div class="form-group">
<label>First and Last Name</label>
<input type="input" id="flname" name="flname" class="form-control" required>
</div>
<div class="form-group">
<label >Email</label>
<input type="email" id="xemail" name="xemail" class="form-control" required>
</div>
<div class="form-group">
<label >Website</label>
<input type="input" id="website" name="website" class="form-control" required>
</div>
<h2> </h2>
<h4>Your Area(s) of Expertise </h4>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Fitness/Wellness"> Fitness/Wellness
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Relationship"> Relationship
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Self-Improvement/ Self-Empowerment"> Self-Improvement/ Self-Empowerment
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Entrepreneurism"> Entrepreneurism
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Money Management"> Money Management
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Travel/Lifestyle Advice"> Travel/Lifestyle Advice
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="services[]" value="Others"> Others
</label>
</div>
<div class="form-group">
<label ><b>Approximately how many clients/readers/followers do you have, combined? </b> </label>
<textarea rows="5" class="form-control" id="approxclient" name="approxclient"></textarea>
</div>
<div class="form-group">
<label><b>Any other thought and comments on the platform</b></label>
<textarea id="comments" name="comments" class="form-control" rows="3"></textarea>
</div>
<h2> </h2>
<button type="submit" class="btn btn-info">Submit</button>
</form>
这是我发送邮件的PHP函数。它无法向邮件发送复选框值,但其他所有内容都正常。
if(!preg_match("/http/i", $_POST['approxclient']) && $_POST['eaid'] == '' && !$_POST['flname'] == '' && !$_POST['xemail'] == '' ) {
$my_email88 = 'email@example.org' . ', '; // note the comma
$subject = "INTERESTED IN PARTNERING";
// Use the submitters email if they supplied one (and it isn't trying to hack your form).
// Otherwise send from your email address.
if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
$headers = "From: $_POST[email]\n";
} else {
$headers = "From: $my_email88\n";
}
//$headers = $headers . "Bcc: put email id here \n";
// prepare a "pretty" version of the message
$message = $message . "Name and Last Name: " . $_POST['flname'] . "\n"; //" " . $_POST['lname'] .
$message = $message . "Email: " . $_POST['xemail'] . "\n";
$message = $message . "Website. " . $_POST['website'] . "\n";
$message = $message . "Your Area(s) of Expertise"."\n";
$services = 'None';
if(isset($_POST['services']) && is_array($_POST['services']) && count($_POST['services']) > 0){
$selectedServices = implode(', ', $_POST['services']);
}
}
答案 0 :(得分:0)
这是我的代码完美运行
$services = 'None';
if(!empty($_POST['services']) && is_array($_POST['services'])){
$message = $message . implode(', ', $_POST['services']). "\n";
}
答案 1 :(得分:-1)
尝试在代码中添加以下内容,
$message = $message . "Your Area(s) of Expertise"."\n";
if(isset($_POST['services']) && is_array($_POST['services']) && count($_POST['services']) > 0){
$selectedServices = implode(', ', $_POST['services']);
foreach($selectedServices as $ss)
{
$message = $message.$ss;
}
}