我通过 Second Life 将数据获取到 PHP 脚本,并且 PHP 脚本通过电子邮件发送数据。
我的问题是如何将时间(即变量 $time)获取到电子邮件的主题行中。现在,它只是忽略变量 $time。
这是我的代码的一部分:
$time = $_POST["time"];
$log = $_POST["log"];
$to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d59a868095b2b8b4bcb9fbb6bab8" rel="noreferrer noopener nofollow">[email protected]</a>";
$subject = <<<TEST
New Visitor; VDC2; $time
TEST;
$theMes = <<<TEST
Visitor Log for VDC2:
$log
TEST;
$headers = 'From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d69585e78595a5879717d5a505c5451135e5250" rel="noreferrer noopener nofollow">[email protected]</a>' . "\r\n" .
'Message-Id: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f2b1a1c3a1b181a3b333f18121e1613511c1012" rel="noreferrer noopener nofollow">[email protected]</a>' . "\r\n" .
'Reply-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5b18086a0818280a1a9a58288848c89cb868a88" rel="noreferrer noopener nofollow">[email protected]</a>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $theMes, $headers);
最佳答案
为什么不这样写 $subject 变量呢?
$subject = "New Visitor; VDC2; " . $time;
当你这样做时,像这样写$theMes:
$theMes = "Visitor Log for VDC2:" . "\n\n" .
$log;
如果这不起作用,请尝试对内容进行编码。我仍然不知道为什么它不会显示,但这可能值得一试,因为邮件确实进行了编码。
$subject = "New Visitor; VDC2; " . $time;
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
分号或时间戳可能会让 PHP 感到困惑。
关于PHP——获取主题行中的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11509497/