带有复选框的PHP联系人表单

带有复选框的PHP联系人表单,php,forms,Php,Forms,我在试着让我的联系方式生效的过程中经历了一段糟糕的时光。我几乎没有php经验。我正试图通过电子邮件将此表单发送给自己,但基本上不知道我在做什么 我需要它通过电子邮件将表单副本发送到我的电子邮件中,并确保复选框显示单击了哪些框 如果有人能帮忙,我将不胜感激 这是我的html <form name="htmlform" method="post" action="send_form_email.php"> <table width="561"> <tr> <

我在试着让我的联系方式生效的过程中经历了一段糟糕的时光。我几乎没有php经验。我正试图通过电子邮件将此表单发送给自己,但基本上不知道我在做什么

我需要它通过电子邮件将表单副本发送到我的电子邮件中,并确保复选框显示单击了哪些框

如果有人能帮忙,我将不胜感激

这是我的html

<form name="htmlform" method="post" action="send_form_email.php">
<table width="561">
<tr>
 <td width="212" align="right" valign="top">
  <label for="name">*Name</label>
 </td>
 <td width="337" valign="top">
  <input  type="text" name="name" maxlength="150" size="50">
 </td>
</tr>
<tr>
 <td valign="top" align="right">
  <label for="company">*Company</label>
 </td>
 <td width="337" valign="top">
  <input  type="text" name="name" maxlength="150" size="50">
 </td>
</tr>
<tr>
 <td valign="top" align="right">
  <label for="telephone">Phone</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="150" size="50">
 </td>
</tr>
<tr>
 <td valign="top" align="right">
  <label for="email">*Email Address</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="180" size="50">
 </td>
 </tr>
 <tr>
 <td valign="top" align="right">
  <label for="services">*Current Services<br />
(check all that apply)</label>
 </td>
 <td valign="top">
<input type="checkbox" name="services[]" value="none" />&nbsp;None<br />

<input type="checkbox" name="services[]" value="coffee" />&nbsp;Coffee<br />

<input type="checkbox" name="services[]" value="vending" />&nbsp;Vending<br />

<input type="checkbox" name="services[]" value="watercoolers" />&nbsp;Water Coolers<br />

<input type="checkbox" name="services[]" value="cafeteria" />&nbsp;Cafeteria<br />

 </td>
 </tr>
<tr>
 <td valign="top" align="right">
  <label for="comments">*Comments</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="40" rows="6"></textarea>
 </td>

</tr>
<tr>
 <td colspan="2" style="text-align:center">
  <center><input type="submit" value="Submit Form"></center>
 </td>
</tr>
</table>
</form>

*名字
*公司
电话
*电子邮件地址
*当前服务
(勾选所有适用项) 无
咖啡
自动售货
水冷却器
自助餐厅
*评论
这是我的php

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "michael@mrugenus.com";
    $email_subject = "Contact form";

    $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 .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Services: ".implode(",", $_POST['services'])."\n";
    $email_message .= "Comments: ".clean_string($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 -->
<center>
<img src="images/logo.png" />
  <br>
  <br>
  Thank you for contacting us.  We will be in touch.<br>
<br>
 <a href="index.html">HOME</a></center>

<?php
}
?>



感谢您联系我们。我们将保持联系。

确定其固定值: PHP文件:

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "someone@gmail.com";
$email_subject = "Contact form";
$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 .= "Name: ".clean_string($_POST["name"])."\n";
$email_message .= "Email: ".clean_string($_POST["email"])."\n";
$email_message .= "Telephone: ".clean_string($_POST["telephone"])."\n";
$email_message .= "Services: ".implode(" ", $_POST['services'])."\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 -->
<center>
<img src="images/logo.png" />
  <br>
  <br>
  Thank you for contacting us.  We will be in touch.<br>
<br>
 <a href="index.html">HOME</a></center>

<?php
}
?>



感谢您联系我们。我们将保持联系。


下面是一个示例代码,它使用
选择
复选框
文本框
启动:

    <form name="prf_form" method="post" action="email.php">
    <input type="text" class=tBox title="This should be a 'C-Level' or VP" id="eSponsor" name="esponsor"></input>
    <select name="sponsorinform">
        <option value="Yes">Yes</option>
        <option value="No" SELECTED>No</option>
    </select>
    <input type=checkbox name="pj_regulatory" value="Regulatory" /> Regulatory<img src="bLine.png" width=20 /><input type=checkbox name="pj_revenhancement" value="Revenue Enhancement" /> Revenue Enhancement
    </form>

你得到了什么成果?@Belinda什么都没有出现。我正在获取成功页面,但没有电子邮件。请尝试打开警告。它可能有助于诊断问题。此外,请仔细检查您的电子邮件地址的拼写是否正确。答案正确吗?如果是,请接受一个。非常感谢。我正在学习php,有点不知所措。非常感谢。这就解决了这个问题。另外,你的html中不应该有相同的name=“name”,对于公司来说,它应该是name=“company”。然后将其传递给post变量$\u post['company'],然后您可以添加:$email\u message.=“company:”.clean\u字符串($\u post[“company”])。“\n”;事实上我也抓到了。我收到的测试邮件没有名字,名字下没有公司名称。谢谢
       // Clean up the input values 
        foreach($_POST as $key => $value) {  
            $_POST[$key] = stripslashes($_POST[$key]); 

            $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key])); 
        }
    $esponsor = trim(strip_tags(stripslashes($_POST['esponsor'])));
    $sponsorinform = trim(strip_tags(stripslashes($_POST['sponsorinform'])));
    $pj_regulatory = trim(strip_tags(stripslashes($_POST['pj_regulatory'])));
    $pj_revenhancement = trim(strip_tags(stripslashes($_POST['pj_revenhancement'])));

    echo $esponsor; //displays the text entered
    echo $sponsorinform; //displays YES or NO
    echo $pj_regulatory;
    echo $pj_revenhancement;

$sentMailSubject = "Project Request From $customerfname $customerlname";

// To send HTML mail, the Content-type header must be set
$sentHeader  = 'MIME-Version: 1.0' . "\r\n";
$sentHeader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
//$to  = 'aidan@example.com' . ', '; // note the comma
//$to .= 'wez@example.com';
// ^^^^^ for multiple email address
$sentHeader .= 'From: ' . $customerfname . ' <' . $userEmail . '>' . "\r\n";

$sentMailBody = "TEST";

$toEmail = "youremail@yourdomain.com, someoneelse@some.com";

mail($toEmail, $sentMailSubject, $sentMailBody, $sentHeader); //send to us