PHP——获取主题行中的时间

标签 php email

我通过 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/

相关文章:

mysql - fatal error : Call to undefined function mysqli_init()

php - 在 PDO 准备好的语句中,请求 HAVING 计数 > 1,这段代码做错了什么

html - Outlook 导致图像之间存在间隙

email - 通过 mailgun 发送电子邮件时出错

php - WordPress 错误 "A variable mismatch has been detected."

php - Codeigniter 路由段/参数

java - MsgViewer (Java) 无法打开 .msg 文件 - 批处理文件解决方案?

django - 发送电子邮件时,发件人标题等于我的 Google Apps 帐户别名,而不是我自己的 Google Apps 帐户

java - 如何从收到的电子邮件中提取信息以自动执行 list ?

php - SQL 查询,汇总某一特定项之前和之后的条目