0

现在我有这个:

$sendtoname = "John";
$sendtoemail = "john@email.com";

还有这个:

$message = "Dear ".$sendtoname;
$message .= ",<br><br>A new volunteer has registered for your ".$_REQUEST['pickevent'];

所以我收到一条消息说,

"Dear John,

A new volunteer has registered for your event..."

但是“约翰”没有出现;它显示为空白。我该如何纠正?

编辑 :

好的,这是我的完整代码:

<?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 = "Dear ".$sendtoname;
$message .= ",<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><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
switch ($_REQUEST["pickevent"])
{
    case 'Heart Walk 4/20/13':
        $sendtoname = "Bob";
        $sendtoemail = "bob@email.com";
        break;
    case 'Bowling Fundraiser 5/4/13':
        $sendtoname = "John";
        $sendtoemail = "john@email.com";
        break;
}

//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 .= "Bcc: me@myemail.com" . "\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 没有出现在消息中。它出现在标题中就好了。

4

1 回答 1

1

将您的开关移至 before $message,因为您在声明之前尝试使用$sendtoname它。

//This is the person who is going to receive the email
switch ($_REQUEST["pickevent"])
{
    case 'Heart Walk 4/20/13':
        $sendtoname = "Bob";
        $sendtoemail = "bob@email.com";
        break;
    case 'Bowling Fundraiser 5/4/13':
        $sendtoname = "John";
        $sendtoemail = "john@email.com";
        break;
}

$message = "Dear ".$sendtoname;
$message .= ",<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><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'];
于 2013-04-11T18:09:45.367 回答