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.

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效