复选框以邮件形式

时间:2014-04-12 03:42:04

标签: php html forms email

我正在尝试创建一个电子邮件表单,用户可以在其中撰写电子邮件,评论并选择他们想要的特定服务。他们可以选择不同的选项。但问题是我得到了这个错误:

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@gmail.com";
  $email_subject = "Design Offer";
  $email_from = "from@from.com";

  $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不是很熟悉:/

2 个答案:

答案 0 :(得分:1)

不要调用表单元素design[1]design[2]等,而是尝试将它们全部命名为design[],如下所示:

<td valign="top">
    <input type="checkbox" name="design[]" 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[]" value="wallpaper" /> Wallpaper <br />
    <input type="checkbox" name="design[]" value="webdesign" /> Web Design <font size="1"><i>(A full web design with code)</i><br /></font>
    <input type="checkbox" name="design[]" value="logo" /> Logo  <br />
    <input type="checkbox" name="design[]" value="logo" /> Other <font size="1"><i>(Write in comment)</i><br /></font>
</td>

PHP应该按照它们包含在页面中的顺序自动将它们连接成一个数组。

答案 1 :(得分:0)

试试这个:

    <input type="checkbox" name="design[]" 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[]" value="wallpaper" /> Wallpaper <br />
    <input type="checkbox" name="design[]" value="webdesign" /> Web Design <font size="1"><i>(A full web design with code)</i><br /></font>
    <input type="checkbox" name="design[]" value="logo" /> Logo  <br />
    <input type="checkbox" name="design[]" value="logo" /> Other <font size="1"><i>(Write in comment)</i><br /></font>