现在我有这个:
$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);
?>
表单正确反应,否则会发送给正确的人并向我发送BCC。所有其他消息也可以正常工作。唯一不起作用的是$ sendtoname不会出现在消息中。它虽然在标题中显示得很好。
答案 0 :(得分:1)
将您的切换移至$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'];