1

我的活动页面有一个 PHP 表单。现在它可以完美地通过电子邮件发送给自己,我可以毫无问题地将它抄送给我喜欢的任何人。但是,如果从我的表单上的下拉框中选择了某个事件,我只想将其发送给特定的人,并将其抄送给我。这样,举办活动的组织就可以收到一份完整表格的副本。如果可能的话,我还想向收件人发送自定义消息。例如:

如果填写表格的人选择了“Heart Walk”活动,那么表格结果应通过“bob@email.com”发送给“Bob”,并附上一条消息:“嗨,Bob,您收到了一位新志愿者为您的 Heart Walk 活动。以下是注册副本。”

当然,我会得到一份副本。

我可以为 $sendtoemail 命令执行 if/then 语句或数组吗?然后通过输入以下内容将其复制给我:

$headers .= "Cc: me@myemail.com\r\n";

最好的方法是什么?谢谢你的帮助!:)

编辑 :

这是我的代码:

<?php
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}

$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}

//send an email from the server TO YOUR EMAIL
$fromname = $_REQUEST['firstname'];
$fromemail = $_REQUEST['email'];
$subject = "NMVN EVENT REGISTRATION";

$message = " <b>EVENT:</b> ".$_REQUEST['pickevent'];
$message .= " <br><br> <b>First Name:</b> ".$_REQUEST['firstname'];
$message .= " <br> <b>Last Name:</b> ".$_REQUEST['lastname'];
$message .= " <br> <b>Cell Phone:</b> ".$_REQUEST['cellphone'];
$message .= " <br> <b>Alternative Phone:</b> ".$_REQUEST['altphone'];

//This is the person who is going to receive the email
$sendtoname = "Mike Gandy";
$sendtoemail = "me@myemail.com";

//Email header stuff
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromname <$fromemail>\r\n";
$headers .= "To: $sendtoname <$sendtoemail>\r\n";
$headers .= "Reply-To: $fromname <$fromemail>\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: Created by Mike Gandy";

//this next line creates and sends the email
mail($sendtoemail, $subject, $message, $headers);

?>

我正在考虑替换这个:

$sendtoname = "Mike Gandy";
$sendtoemail = "me@myemail.com";

有了这个:

if ($_REQUEST['pickevent'] == 'HeartWalk'))
//if "HeartWalk" is filled out, send to email
  {
  //send email
  $sendtoname = "Bob";
  $sendtoemail = "bob@email.com";
  }
elseif ($_REQUEST['pickevent'] == 'RaceCure'))
//if "RaceCure" is filled out, send to email
  {
  //send email
  $sendtoname = "Susan";
  $sendtoemail = "susan@email.com";
  }  
elseif ($_REQUEST['pickevent'] == 'Bowling'))
//if "Bowling" is filled out, send to email
  {
  //send email
  $sendtoname = "John";
  $sendtoemail = "john@email.com";
  }

但另外我需要要求选择一个事件,所以“其他”将是一个弹出窗口,上面写着“选择一个事件!”。这有帮助吗?

最后编辑:

好的,所以我得到了验证。谢谢你。我正在替换这个:

$sendtoname = "Mike Gandy";
$sendtoemail = "me@myemail.com";

有了这个:

switch(strtolower($event){
    case 'HeartWalk':
        $sendtoname('Bob')
        $sendtoemail('bob@email.com');
        break;
    case 'RaceCure':
        $sendtoname('Susan')
        $sendtoemail('susan@email.com');
        break;
    case 'Bowling':
        $sendtoname('John')
        $sendtoemail('john@email.com');
        break;
}

添加这个:

$headers .= "Cc: somebody@domain.com" . "\r\n";

并将我的消息的开头更改为:

$message = "Dear $sendtoname, <br><br>A new volunteer has registered for your "$_REQUEST['pickevent'];
$message .= " event. Below is a copy of their registration: ".$_REQUEST['blank'];
$message .= " <br><br> <b>First Name:</b> ".$_REQUEST['firstname'];

并将其包含在我的表格中:

<input type="hidden" name="blank" value="">

是的?不?

4

2 回答 2

1
  1. 使用selectHTML 标签创建下拉菜单:

    <select name="event">
    <option value="heartwalk">Heart Walk</option>
    <option value="other">Other</option>
    </select>
    
  2. 处理帖子时,请使用$_REQUEST["event"]for 决策,例如:

    switch ($_REQUEST["event"])
    {
    case 'heartwalk':
        $sendtoemail = "heartwalk@example.com";
        break;
    default:
        $sendtoemail = "other@example.com";
        break;
    }
    
  3. 对于验证,您可以在提交表单时从客户端的 JavaScript 验证开始。例如参考: https ://www.tutorialspoint.com/javascript/javascript_form_validations.htm

当然,也建议在服务器端进行一些验证。根据您希望系统的健壮程度,您可以从不做任何事情开始将浏览器重定向回表单并在页面上显示消息。

于 2013-04-11T15:40:46.953 回答
1

你可以试试switch语句。

switch(strtolower($event){
    case 'heart walk':
        $sendtoemail('bob@email.com');
        break;
    case 'some other walk':
        $sendtoemail('theotherguy@email.com');
        break;
    default:
        $sendtoemail('info@email.com');
        break;
}
于 2013-04-11T15:37:59.613 回答