doumi9661 2013-06-06 16:48
浏览 30
已采纳

将多个复选框值发布到php电子邮件中

I am brand new to php. I would like to post multiple checkbox values in an email from a form when they are selected. Only the last option checked is coming through in the email, even if they are all selected in the form. I have tried many solutions I found on for this and can't seem to find one that works for me.

What am I doing wrong?

HTML:

        <input type="checkbox" name="product-types-owned[]" value="Cast_Iron" /> 
        <input type="checkbox" name="product-types-owned[]" value="Braisers" />
        <input type="checkbox" name="product-types-owned[]" value="Ovens" />
        <input type="checkbox" name="product-types-owned[]" value="Skillet" />

php:

        $sendto   = "email@email.com";
        $usermail = $_POST['Email'];
        $firstname  = nl2br($_POST['First_name']);
        $lastname  = nl2br($_POST['Last_name']);
        $address1  = nl2br($_POST['Address1']);
        $address2  = nl2br($_POST['Address2']);
        $city = nl2br($_POST['City']);
        $state = nl2br($_POST['State']);
        $zip = nl2br($_POST['Zip_Code']);
        $phone = nl2br($_POST['Telephone']);
        $ownership = nl2br($_POST['product-types-owned']); 

        $subject  = "Product Registration";
        $headers  = "From: " . strip_tags($usermail) . "
";
        $headers .= "Reply-To: ". strip_tags($usermail) . "
";
        $headers .= "MIME-Version: 1.0
";
        $headers .= "Content-Type: text/html;charset=utf-8 
";

        $msg  = "<html><body style='font-family:Arial,sans-serif;'>";
        $msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Product Registration</h2>
";
        $msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>
";
        $msg .= "<p><strong>First Name:</strong> ".$firstname."</p>
";
        $msg .= "<p><strong>Last Name:</strong> ".$lastname."</p>
";
        $msg .= "<p><strong>Address:</strong> ".$address1."</p>
";
        $msg .= "<p><strong>Address Line 2:</strong> ".$address2."</p>
";
        $msg .= "<p><strong>State:</strong> ".$state."</p>
";
        $msg .= "<p><strong>Zip:</strong> ".$zip."</p>
";
        $msg .= "<p><strong>Telephone:</strong> ".$phone."</p>
";
        $msg .= "<p><strong>Products Own or Intend to Own:</strong> ".$ownership."</p>
";
        $msg .= "</body></html>";

I have tried the solution here as well as changing

$ownership = nl2br($_POST['product-types-owned']);

to

$ownership = nl2br(implode(',', $_POST['product-types-owned']));

and I get an error: Warning: implode() [function.implode]: Invalid arguments passed in /home/content/99/11039499/html/scripts/warranty.php on line 24

Please help, I am so frustrated.

  • 写回答

1条回答 默认 最新

  • doucang6914 2013-06-06 16:52
    关注
        $ownership = nl2br($_POST['product-types-owned']); 
    

    product-types-owned is going to be an array of the checkbox values that were selected. You'll need to implode that before you do anything else:

    $ownership = nl2br(implode(',', $_POST['product-types-owned']));
    

    Right now you're trying to nl2br on an array, which won't work. nl2br expects a string, so php will type cast the array into its default string representation, which is literally the word Array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化