【问题标题】:Trying to add $sendtoname to message尝试将 $sendtoname 添加到消息
【发布时间】:2013-04-11 17:57:28
【问题描述】:

现在我有这个:

$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 没有出现在消息中。它出现在标题中就好了。

【问题讨论】:

  • 对不起?约翰是否出现在消息中?
  • 不,当我收到电子邮件时,John 没有出现在邮件中。
  • 在您创建$message 的位置是否可见$sendtoname$message$sendtoname 是在函数中创建的吗?
  • @MikeGandy - 你能添加更多代码吗?您发布的内容没有明显问题,所以问题可能出在其他地方。
  • 刚刚用我的所有代码编辑了我的帖子。有什么建议么?谢谢你们的帮助,伙计们!

标签: php email message


【解决方案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'];

【讨论】:

  • 那是因为填写表格的人没有收到消息。这是一个活动页面,而志愿者注册,结果将发送给活动组织者并密件抄送给我。
  • 查看我编辑的答案。您正在尝试在声明之前使用$sendtoname
猜你喜欢
  • 2014-02-23
  • 2014-08-26
  • 2020-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 2021-10-12
相关资源
最近更新 更多