Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于确定邮件目的地的PHP复选框_Php_Forms_Post - Fatal编程技术网

用于确定邮件目的地的PHP复选框

用于确定邮件目的地的PHP复选框,php,forms,post,Php,Forms,Post,我有一个我使用的邮件表单。在新用法中,我添加了两个复选框。我希望能够根据复选框将邮件发送到不同的地址。 例如:如果“框1”选中“邮寄给xx”,如果“框2”选中“邮寄给xx”,则同时邮寄给两者。我用来邮寄的代码是: <? /************************ * Variables you can change *************************/ $mailto = ""; $cc = ""; $bcc = ""; $subject = "contact"

我有一个我使用的邮件表单。在新用法中,我添加了两个复选框。我希望能够根据复选框将邮件发送到不同的地址。 例如:如果“框1”选中“邮寄给xx”,如果“框2”选中“邮寄给xx”,则同时邮寄给两者。我用来邮寄的代码是:

<?

/************************
* Variables you can change
*************************/

$mailto = "";
$cc = "";
$bcc = "";
$subject = "contact";
$vname = "Enquiry";


/************************
* do not modify anything below unless you know PHP/HTML/XHTML
*************************/
/* my trial adjustment for check boxes
*/


$email = $_POST['email'];

function validateEmail($email)
{
   if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
      return true;
   else
      return false;
}


if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){
    $emailerror .= '';

    if(strlen($_POST['name']) < 1 ){
        $emailerror .= '<li>Enter name</li>';
    }

    if(strlen($email) < 1 ){
        $emailerror .= '<li>Enter email</li>';
    }

    if(validateEmail($email) == FALSE) {
        $emailerror .= '<li>Enter valid email</li>';
    }

    if(strlen($_POST['message']) < 1 ){
        $emailerror .= '<li>Enter message</li>';
    }

} else {

    $emailerror .= "Your email has been sent successfully";



    // NOW SEND THE ENQUIRY

    $timestamp = date("F j, Y, g:ia");

    $messageproper ="\n\n" .
        "Name: " .
        ucwords($_POST['name']) .
        "\n" .
        "Email: " .
        ucwords($email) .
        "\n" .
        "Telephone Contact: " .
        ucwords($_POST['tel']) .
        "\n" .
        "Company: " .
        ucwords($_POST['company']) .
        "\n" .
        "Comments: " .
        $_POST['message'] .
        "\n" .
        "\n\n" ;

        $messageproper = trim(stripslashes($messageproper));
        mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() );

}
?>

<div id='emailerror'>
    <ul>
        <? echo $emailerror; ?>
    </ul>
</div>

复选框代码:

   <label>MailPersonA</label>
    <input type="checkbox" name="A" value="checkbox" id="A" />
   <label>MailPersonB</label>
      <input type="checkbox" name="B" value="checkbox" id="B" />
MailPersonA
邮递员

任何帮助都将不胜感激。

您可能会在以下方面做得更好:

   <label>MailPersonA</label>
    <input type="checkbox" name="emailadd[]" value="email1@example.com" id="A" />
   <label>MailPersonB</label>
      <input type="checkbox" name="emailadd[]" value="email2@example.com" id="B" />
根据表单中的值将电子邮件添加到后端可能是一个好主意,而不是像我在这里所做的那样将它们正确地放在表单中。我只是为了举例而简化。

您可能想要:

  • 使用无线电输入而不是复选框,以确保选择了一个
  • 给收音机起相同的名字
  • 给他们不同的价值观
所以你的HTML是

<label>MailPersonA</label>
<input type="radio" name="toaddress" value="person1@wherever.com" id="A" />
<label>MailPersonB</label>
<input type="radio" name="toaddress" value="person2@wherever.com" id="B" />
MailPersonA
邮递员

现在
$\u POST['toaddress']
将包含目标电子邮件地址。

我同意应该在后端映射电子邮件地址。如果电子邮件地址本身在
POST
数据中传递,那么恶意的人可能会使用该表单向您的web服务器发送垃圾邮件。我相信
$\u POST['toaddress'的顺序是正确的
要保存这两个地址,您需要在表单中使用
name=“toaddress[]”
。然后这两个值将以数组形式存在于
$\u POST['toaddress']
中。是的。我正试图让用户只选择一个电子邮件地址。哦,我现在看到了您的
type=“radio”
。我的错:
<label>MailPersonA</label>
<input type="radio" name="toaddress" value="person1@wherever.com" id="A" />
<label>MailPersonB</label>
<input type="radio" name="toaddress" value="person2@wherever.com" id="B" />