1

***编辑** * ***

我已经成功了。现在我只帮助一件简单的小事:如何让电子邮件用逗号分隔每个复选框选择?

所以代替:

感兴趣:每小时销售线索生成 B2B 销售

它应该是:

感兴趣:每小时销售线索生成,B2B 销售

谢谢,内森


我刚刚在这个网站上注册,希望能得到一些帮助,让我的表格可以通过电子邮件发送复选框选择。

我几乎是一个 php 的菜鸟,但使用 lynda.com 我的联系表格至少可以工作 - 现在我只需要选择复选框来发送电子邮件。

这是我的表格:

<form id="mainForm" method="post" name="contact" action="http://www.digicrest.com/sales/contactFormProcess.php">
                        <ul>
                            <li>Name<span>*</span> <br/>
                                <input class="form2" name="name" type="text" />
                            </li>
                            <li>Email Address<span>*</span> <br/>
                                <input class="form2" name="email" type="text" />
                            </li>
                            <li>Subject<span>*</span> <br/>
                                <input class="form2" name="subject" type="text" />
                            </li>                            
                            <li>Company<span>*</span> <br/>
                                <input class="form2" name="company" type="text" />
                            </li>
                            <li>Phone Number <br/>
                                <input class="form2" name="phone" type="text" />
                            </li>                            
                            <li id="checkboxes">
                                I'm Interested In:
                                <br />
                                <div><input type="checkbox" name="interested[]" value="Pay For Performance Appointment Setting" class="checkbox" id="option1" /> Pay For Performance Appointment Setting
                                    <br />
                                    <input type="checkbox" name="interested[]" value="Hourly Sales Lead Generation" class="checkbox" id="option2" /> Hourly Sales Lead Generation
                                    <br />
                                    <input type="checkbox" name="interested[]" value="B2B Sales" class="checkbox" id="option3" /> B2B Sales
                                    <br />
                                    <input type="checkbox" name="interested[]" value="Inbound Lead Generation" class="checkbox" id="option4" /> Inbound Lead Generation
                                </div>
                            </li>
                            <li><span class="clearLeft"></span></li>
                            <div class="clearLeft"></div>

                            <li>Comments / Details<span>*</span> <br/>
                                <textarea class="form2B" cols="20" rows="6" name="message"></textarea>
                            </li>                            
                        </ul>

                        <div id="formButtons2">
                            <input class="clear2" type="reset" value=""/> 
                            <input class="submit" type="image" name="submit" src="images/send-big.jpg" alt="" />
                        </div>
                    </form>

- 这是我的 php-

<?php

/* Subject and Email Variables */

$emailSubject = $_POST['subject'];
$webMaster = 'info@digicrest.com';
$email = $_POST['email'];

/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$companyField = $_POST['company'];
$phone = $_POST['phone'];
$messageField = $_POST['message'];
$interestedField = implode(' ', $_POST['interested']);

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Subject: $subjectField <br>
Company: $companyField <br>
Phone: $phone <br>
Interested In: $interestedField <br>
Message: $messageField <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results Rendered as HTML */

$theResults = <<<EOD
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Welcome To Sales Source Lead Generation - B2B Solutions</title>
        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <link href='http://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css' />
        <link rel="stylesheet" href="css/basic-jquery-slider.css" />
    </head>

    <body>
        <!-- header -->
        <div id="pageArea">
            <div id="headerArea">
                <div id="header">
                    <div class="content">
                        <a id="logo" href="index.html" title="Home"><img src="images/logo.jpg" width="198" height="102" alt=""/></a> 

                        <div id="phone">
                            Call us Toll Free: <span>1-888-557-4223</span>  Ext 2
                        </div> 

                        <div id="navbar">
                            <div id="home"><a href="index.html" title="Home"></a></div>
                            <div> | </div>
                            <div id="about"><a href="about.html" title="About Us"></a></div>
                            <div> | </div>
                            <div id="services"><a href="services.html" title="Services"></a></div>
                            <div> | </div>
                            <div id="faq"><a href="faq.html" title="FAQ"></a></div>
                            <div> | </div>
                            <div id="rep"><a href="rep.html" title="Become a Rep"></a></div>
                            <div> | </div>
                            <div id="contact"><a href="contact.html" title="Contact Us"><img src="images/contact-current.jpg" width="87" height="16" alt="" /></a></div>
                        </div>

                        <div class="clearer"></div>
                    </div>
                </div>
            </div>
            <div id="barArea2">
                <div class="content">
                    <div id="light"><img src="images/light.png" width="787" height="493" alt="" /></div>
                    <h1 class="pageTitle">Message Sent!</h1>
                </div>                
            </div>

            <div id="hr"></div>

            <div class="contentArea">                
                <div class="content">
                    <div align="center">Thank you for your message! Your email will be answered as soon as possible!
                        <br />
                        <br />
                        <a href="index.html" title="Home">Click To Go Back!</a>
                    </div>
                </div>
            </div>
            <div class="clearer"></div>           


        </div>

    </body>
</html>

EOD;
echo "$theResults";
?>

我很感激任何帮助:)

谢谢阅读。

-内森

4

2 回答 2

0

在您的情况下,您的复选框存储在$_POST['interested']数组中。因此,您需要包括它们的内爆形式 ( $interestedField)。

如果你想要逗号,只需用 implode", "代替" ".

于 2012-12-05T17:13:55.480 回答
0

假设一切正常:

/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$choices = implode(", ", $_POST['interested']);

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Subject: $subjectField <br>
Email: $emailField <br>
Message: $messageField <br>
Choices: $choices
EOD;

请注意,这只会为您提供复选框的值(例如:1、2、3、4)而不是文本(例如:“支付绩效预约设置”)。为了得到这个,你需要在你的 PHP 中的某个地方有这些文本:

$labels = array("1"=>"Pay For Performance Appointment Setting",
          "2"=>"Hourly Sales Lead Generation",
          "3"=>"B2B Sales",
          "4"=>"Inbound Lead Generation");

/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$choices = array();
foreach($_POST['interested'] as $choice) {
    $choices[] = $labels[$choice];
}
$choices = implode(", ", $choices);

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Subject: $subjectField <br>
Email: $emailField <br>
Message: $messageField <br>
Choices: $choices
EOD;

希望这可以帮助。

编辑:好的,您在我回答时更改了您的帖子,以便复选框的值包含使我回答的第二部分多余的文本。如果您想将数据保存到数据库中,最好的方法是使用数值,并将描述存储在其他地方。

于 2012-12-05T17:14:55.237 回答