0
我試圖創建一個電子郵件表單,其中一個人寫他們的電子郵件,評論和選擇他們想要的特定服務。他們可以選擇不同的選項。但問題是,我得到這個錯誤:郵件格式的複選框
Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\html_form_send.php on line 43
order.php
<form name="htmlform" method="post" style="margin: 0; padding: 0;" action="html_form_send.php">
<table width="900px">
</tr>
<tr>
<td valign="top">
<label for="email" style="font-weight: bold">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="selection" style="font-weight: bold">Choose what you want me to make *</label>
</td>
<td valign="top">
<input type="checkbox" name="design[1]" value="twitch_design" /> Twitch Design <font size="1"><i>(Includes offline background, buttons or headers, wallpaper, cam overlay)</i><br /></font>
<input type="checkbox" name="design[2]" value="wallpaper" /> Wallpaper <br />
<input type="checkbox" name="design[3]" value="webdesign" /> Web Design <font size="1"><i>(A full web design with code)</i><br /></font>
<input type="checkbox" name="design[4]" value="logo" /> Logo <br />
<input type="checkbox" name="design[5]" value="logo" /> Other <font size="1"><i>(Write in comment)</i><br /></font>
</td>
</tr>
<tr>
<td valign="top">
<label for="comments" style="font-weight: bold">Comment *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<br />
<input type="submit" class="submit" value="SEND ORDER">
</td>
</tr>
</table>
</form>
html_form_send.php:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Design Offer";
$email_from = "[email protected]";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Email: ".clean_string($_POST["email"])."\n";
$email_message .= "Design type: ".implode(",", $_POST['design'])."\n";
$email_message .= "Comments: ".clean_string($_POST["comments"])."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch.
<?php
}
?>
我得提醒你,我不是很熟悉PHP:/
哇,謝謝。如果所需的字段未被選中,是否可以添加錯誤消息? – user3524703
當然,只要測試變量的存在,例如'$ errors = [];如果(!$ _ POST ['design'])$ errors [] =「您至少需要選擇一種設計。 ... if($ errors){echo'
'.implode('
', $errors).'
http://www.w3schools.com/php/php_form_validation.asp – linesarefuzzy